DEV Community

John Au-Yeung
John Au-Yeung

Posted on • Originally published at thewebdev.info

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

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");
Enter fullscreen mode Exit fullscreen mode

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.

Top comments (0)