Answers for "condition with empty array js"

24

javascript check if array is empty

if (typeof array !== 'undefined' && array.length === 0) {
    // the array is defined and has no elements
}
Posted by: Guest on March-13-2020
4

check if an array is empty javascript

if (!Array.isArray(array) || !array.length) {
  // array does not exist, is not an array, or is empty
  // ⇒ do not attempt to process array
}
Posted by: Guest on October-03-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language