0.1.1-4 • Published 6 years ago

javascript-array-search v0.1.1-4

Weekly downloads
36
License
MIT
Repository
github
Last release
6 years ago

JavaScript Array Search

Installation

Using npm:

$ npm install --save javascript-array-search

Or yarn:

$ yarn add javascript-array-search

Usage

Iterates over elements of collection, returning an array of all elements where any their specified fields include every word in the term string.

Arguments

parametertypedescription
collectionArrayThe collection to iterate over
termstringThe search term
fieldsArrayThe 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']
0.1.1-4

6 years ago

0.1.1-3

6 years ago

0.1.1-2

6 years ago

0.1.1-1

6 years ago