DEV Community

Discussion on: How to check if an array is empty using Javascript?

Collapse
 
jonrandy profile image
Jon Randy 🎖️ • Edited

Why so long?

const isEmptyArray = a=>Array.isArray(a) && !a.length
Enter fullscreen mode Exit fullscreen mode

Checking it is an Array is also not necessary, so you can just do:

const isEmptyArray = a=>!a.length
Enter fullscreen mode Exit fullscreen mode