DEV Community

Sujit Kar
Sujit Kar

Posted on • Edited on

How to check an Array is empty or not in Javascript?

There is a very simple technique to check whether an array is empty or not.

const arr = [];
if(arr.length === 0){
 console.log("Array is empty");
}
else{
 console.log("Array is not empty");
}
Enter fullscreen mode Exit fullscreen mode

Get in touch with me.

Thanks!!!
@sujitkar1195

Top comments (1)

Collapse
 
arpita_guria_0c509d5e38ae profile image
Arpita Guria

In JavaScript ,to check if an array is empty or not , we can check its length property.