javascript - How to check if array is empty or does not exist? - Stack Overflow

PHOTO EMBED

Sun Feb 13 2022 13:59:54 GMT+0000 (Coordinated Universal Time)

Saved by @arielvol #javascript

if (!Array.isArray(array) || !array.length) {
  // array does not exist, is not an array, or is empty
  // ⇒ do not attempt to process array
}

or 

if (!array?.length) {
    // array or array.length are falsy
    // ⇒ do not attempt to process array
}
content_copyCOPY

https://stackoverflow.com/questions/24403732/how-to-check-if-array-is-empty-or-does-not-exist