0.1.1-4 • Published 7 years ago
javascript-array-search v0.1.1-4
JavaScript Array Search
Installation
Using npm:
$ npm install --save javascript-array-searchOr yarn:
$ yarn add javascript-array-searchUsage
Iterates over elements of collection, returning an array of all elements where any their specified fields include every word in the term string.
Arguments
| parameter | type | description |
|---|---|---|
collection | Array | The collection to iterate over |
term | string | The search term |
fields | Array | The element's fields to be searched. |
Returns
ArrayReturns the new filtered array.
Example
const users = [
{ 'user': 'Barney Rubble', 'age': 36 },
{ 'user': 'Fred Flintstone', 'age': 40 },
{ 'user': 'Pebbles Flintstone', 'age': 1 }
];
search(users, 'Fred Flint', ['user']);
// => objects for ['Fred Flintstone']
search(users, 'Flintstone', ['user'])
// => objects for ['Fred Flintston', 'Pebbles Flintstone']
search(users, '3', ['age']);
// => objects for ['Barney Rubble']
search(users, 'Flintstone 1', ['user', 'age']);
// => objects for ['Pebbles Flintstone']