existsBy (source code)
- Curried: true
- Failsafe status: alternative available
The existsBy
function searches for an item in the array that matches the
provided pattern and returns true if found, or false otherwise.
pattern
: The pattern using which an object will be matched.entityArray
: The array of objects in which the object with the given pattern will be searched.
const array = [
{ id: 1, name: "Sam", address: { street: "First street", pin: 101283 } },
{ id: 2, name: "Oliver", address: { street: "Second street", pin: 998472 } },
];
existsBy({ name: "Sam" }, array); // true
existsBy({ name: "Harry" }, array); // false