Reputation: 221
I have an array variable like Array[0]
, and now I need to check whether that Array[0]
contains value or not inside of it. What should I do?
Upvotes: 1
Views: 365
Reputation: 1284
Checks if that array exists and does something if not so.
if(!array[0])
{
//do something
}
Upvotes: 1
Reputation:
//pass array variable to this function
function isEmpty(array){
if(array.length == 0)
return true;
else
return false;
}
Upvotes: 1
Reputation: 137350
If you have an array and call it eg. list
, then you can check if it has some elements in the following manner:
if (list.length){
// has some elements (exactly list.length elements)
} else {
// does not have any elements
}
See the following for details: Documentation on length
property of Array
objects in JavaScript
Upvotes: 3