xxxxxxxxxx
var colors=[];
if(!colors.length){
// I am empty
}else{
// I am not empty
}
xxxxxxxxxx
if (typeof array !== 'undefined' && array.length === 0) {
// the array is defined and has no elements
}
xxxxxxxxxx
if(typeof array != 'undefined' && array.length > 0){
// array has elements
}
xxxxxxxxxx
if (!Array.isArray(array) || !array.length) {
// array does not exist, is not an array, or is empty
// ⇒ do not attempt to process array
}
xxxxxxxxxx
if (array === undefined || array.length == 0) {
// array empty or does not exist
}
xxxxxxxxxx
arr = []; // set array=[]
//function
const empty = arr => arr.length = 0;
//example
var arr= [1,2,3,4,5];
empty(arr) // arr=[]
xxxxxxxxxx
if (typeof image_array !== 'undefined' && image_array.length > 0) {
// the array is defined and has at least one element
}
xxxxxxxxxx
const isNotEmpty = arr => Array.isArray(arr) && arr.length > 0;
isNotEmpty([1, 2, 3]);
// Result: true