Find(Array array, [Function, Object] predicate)
Finds the first item from *Array* array that returns true from *[Function, Object]* predicate.
For array - Collection of items to iterate over with *[Function, Object]* predicate.
For Function
: *Function* to invoke per item of *Array* array to determine if an item has been found. *Function* predicate should return *Boolean* true || false
.
import { Find } from "@taystack/js-helpers";
const items = [{a: 1, b: 1}, {a: 2, b: 1}, {a: 3, b: 1}];
// Function predicate
const found = Find(items, (item) => (item.a === 2));
// Shorthand Object predicate
const shorthand = Find(items, {a: 2});
Source: @taystack/js-helpers hosted on GitHub Author: taystack