js check if array is empty

How to check if array is empty or null or undefined in javascript?

Syntax Code

if (productInfoArr && productInfoArr.length > 0) {
   console.log('productInfoArr is not empty.');
}else{
   console.log('productInfoArr is empty.');
}

Example:




    How to check if array is empty or null or undefined in javascript? - ItSolutionStuff.com


  



Results

productInfoArr is not empty.
productInfoArr2 is empty.
productInfoArr3 is empty.
productInfoArr4 is empty.

Leave a Comment