Categories
JavaScript Answers

How to use Array.includes() to find object in array with JavaScript?

Spread the love

To use Array.includes() to find object in array with JavaScript, we use the some method.

For instance, we write

const arr = [{ a: "b" }];
console.log(arr.some((item) => item.a === "b"));

to call arr.some with a callback that checks if item in arr has property a equal to 'b'.

If any object in arr has property a equal to 'b' then it returns true.

By John Au-Yeung

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

Leave a Reply

Your email address will not be published. Required fields are marked *