Categories
JavaScript Answers

How to find if object property exists in an array with Lodash and JavaScript?

Spread the love

To find if object property exists in an array with Lodash and JavaScript, we use the has method.

For instance, we write

const countries = { country: { name: "France" } };
const isExist = _.has(countries, "country.name");

to call has with the countries object and the property to look for in each object.

Therefore, isExist is true since country.name is in the countries object.

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 *