1if (typeof array !== 'undefined' && array.length === 0) {
2 // the array is defined and has no elements
3}
4
1if (array === undefined || array.length == 0) {
2 // array empty or does not exist
3}
4
1if (array && !array.length) {
2 // array is defined but has no element
3}
1var colors=undefined;
2if(!colors?.length){
3 console.log("empty")
4}else{
5 // I am not empty
6}