Categories
JavaScript Answers

How to find first element of array matching a boolean condition in JavaScript?

Spread the love

To find first element of array matching a boolean condition in JavaScript, we use the find method.

For instance, we write

const result = someArray.find(isNotNullNorUndefined);

to call someArray.find with the isNotNullNorUndefined function which returns the boolean condition we’re looking for.

The first item with the condition if it’s found.

By John Au-Yeung

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

Leave a Reply

Your email address will not be published.