Skip to content

Latest commit

 

History

History
29 lines (20 loc) · 850 Bytes

existsBy.md

File metadata and controls

29 lines (20 loc) · 850 Bytes

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.

Arguments:

  • 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.

Usage:

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

See also