Has((Array array | Object object | String string), target, [Function predicate=JsHelpers.isTruthy])
Checks if *Array* array returns true from *Function* predicate.
For array - Collection of items to iterate over with *Function* predicate.
For object - object.keys() includes target.
For string - Checks if *String* string contains target.
Function to invoke per item of *Array* array to get a compare value. *Function* predicate should return the value intended to use as a compare value. Iteration is stopped once predicate(target) === predicate(array[i])
.
import { Has } from "@taystack/js-helpers";
const items = [5,6,7,8,9];
Has(items, 5); // true
const collection = [{id: 1}, {id: 2}];
target = {id: 1};
Has(collection, target, x => x.id); // false
Source: @taystack/js-helpers hosted on GitHub Author: taystack