0.2.1 • Published 5 years ago

find-indices v0.2.1

Weekly downloads
2
License
ISC
Repository
github
Last release
5 years ago

find-indices

Build Status

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 search
  • predicate (Function | Array | Object | string) The function invoked per iteration
  • fromIndex number The index to search from (optional, default 0)
  • 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]

Returns Array<number> The array of found indexes