DEV Community

Discussion on: 1 line of code: How to check if an Array is empty

Collapse
 
humansprout profile image
Erik Waters

IMO the utility of this function depends on how you interpret an array being "empty": if you pass an array of empty items the result may not be what the user expects

let arr = Array(2) // [ <2 empty items> ]
isEmptyArray(arr) // false
Enter fullscreen mode Exit fullscreen mode
Collapse
 
lizy0329 profile image
lizy0329

lodash not be user expects too

const arr = Array(2)
_.isEmpty(arr);
=>
false

Some comments have been hidden by the post's author - find out more