Categories
JavaScript Answers

How to check if an array is empty or exists with JavaScript?

Spread the love

To check if an array is empty or exists with JavaScript, we use the Array.isArray method and the array’s length property.

For instance, we write

if (Array.isArray(array) && array.length) {
  // ...
}

to check if array is an array with Array.isArray.

And then we use array.length to check if it’s bigger than 0 to check if it’s filled with content.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published.