1if (typeof array !== 'undefined' && array.length === 0) {
2 // the array is defined and has no elements
3}
4
1if(typeof array != 'undefined' && array.length > 0){
2 // array has elements
3}
1var colors=[];
2if(!colors.length){
3 // I am empty
4}else{
5 // I am not empty
6}
1let myArray = [];
2
3if( myArray.length > 0 ) {
4 console.log(myArray);
5 console.log("Array has elements");
6}
7else {
8 console.log("Array has no elements");
9}