js-helpers

Has

Has((Array array | Object object | String string), target, [Function predicate=JsHelpers.isTruthy])

Checks if *Array* array returns true from *Function* predicate.

Arguments

(Array array | Object object | String string)

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 predicate=JsHelpers.isTruthy]

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]).

Use

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