Featured post
- Get link
- X
- Other Apps
How to check a javascript array is empty or not empty using length property of array
In this article, i will explain How to check an array is empty or not empty using length property of array.If an array has no elements ,then its length property is zero .If an array has elements,then its length property is the number of elements in that array .So using length property of array, we can easily check that the given array contains any elements
let numsArray1 = [];
if(Array.isArray(numsArray1) && numsArray1.length >0){
console.log("numsArray1 is not an empty array")
}else{
console.log("numsArray1 is an empty array")
} //numsArray1 is an empty array
let numsArray2 = [1,2,3];
if(Array.isArray(numsArray2) && numsArray2.length >0){
console.log("numsArray2 is not an empty array")
}else{
console.log("numsArray2 is an empty array")
} //numsArray2 is not an empty array
Popular Posts
How to Check React Version Installed in Your System by Checking PACKAGE.JSON File and Executing Command from COMMAND PROMPT
- Get link
- X
- Other Apps
Execution failed for task ':react-native-reanimated:externalNativeBuildDebug' solved
- Get link
- X
- Other Apps
Error: Invalid `prisma.$executeRaw()` invocation: fixed using log: ["query"] option
- Get link
- X
- Other Apps
app keeps stopping error solved in android studio emulator using logcat in react native project
- Get link
- X
- Other Apps
ERROR Warning: React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined
- Get link
- X
- Other Apps