To determine if JavaScript array contains an object with an attribute that equals a given value, we use the find
method,.
For instance, we write
if (vendors.find((e) => e.name === "foo")) {
//...
}
to call find
with a function that checks if the name
property of the objects in the vendors
array has value 'foo'
.
If it’s true, then the first object that matches the condition will be returned.