find-indices
v0.2.1
Published
Returns indexes of elements in an array that satisfy a predicate
Downloads
46
Readme
find-indices
Returns indexes of elements in an array that satisfy a predicate or a lodash iteratee shorthand.
Like lodash.findindex, but returns all indexes instead of the first one.
Install
npm install find-indices --save
API
find-indices
Parameters
array
Array The array to searchpredicate
(Function | Array | Object | string) The function invoked per iterationfromIndex
number The index to search from (optional, default0
)limit
number The maximum number of indexes to search (optional, default-1
)
Examples
import findIndexes from 'find-indices';
const coll = [{ v: 0 }, { v: 2 }, { v: 0 }, { v: 3 }, { v: 3 }];
findIndexes(coll, ({ v }) => v > 1); // [1, 3, 4]
findIndexes(coll, { v: 0 }); // [0, 2]
findIndexes(coll, ['v', 3]); // [3, 4]
findIndexes(coll, 'v'); // [1, 3, 4]