Q:

javascript how to check if array is empty

if (typeof array !== 'undefined' && array.length === 0) {
    // the array is defined and has no elements
}
4
if (array && !array.length) {
    // array is defined but has no element
}
9
if (Array.isArray(array) && array.length) {
    // array exists and is not empty
}
5
if (array === undefined || array.length == 0) {
    // array empty or does not exist
}
0
var colors=[];
if(!colors.length){
	// I am empty
}else{
	// I am not empty
}
2
if(array.length > 0)
1
if (typeof image_array !== 'undefined' && image_array.length > 0) {
    // the array is defined and has at least one element
}
1
Array.isArray(emptyArray) && emptyArray.length
0
array.length = []
1

New to Communities?

Join the community