W Saed
0
Q:

how to check an empty array js

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
arr = [];   // set array=[]

//function
const empty = arr => arr.length = 0;
//example
var arr= [1,2,3,4,5];
empty(arr) // arr=[]
10
if (array === undefined || array.length == 0) {
    // array empty or does not exist
}
0
var colors = ["red","blue","green"];
    colors = []; //empty the array
9
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

New to Communities?

Join the community