UNPKG

@extra-array/find-index

Version:

Finds index of leftmost value passing a test.

41 lines (32 loc) 1.47 kB
Finds index of leftmost value passing a test. [:running:] [:vhs:] [:package:] [:moon:] [:ledger:] > Alternatives: [findIndex], [findIndices].<br> > Similar: [find], [findIndex].<br> > This is part of package [extra-array]. [extra-array]: https://www.npmjs.com/package/extra-array ```javascript array.findIndex(x, fn); // x: an array // fn: test function (v, i, x) // --> index of value, -1 if not found ``` ```javascript const array = require('extra-array'); var x = [1, 2, 3, 4, 5]; array.findIndex(x, v => v % 2 == 0); // 1 ^ array.findIndex(x, v => v % 2 == 1); // 0 ^ ``` ### references - [Data.List.findIndex: Haskell](http://hackage.haskell.org/package/base-4.12.0.0/docs/Data-List.html#v:findIndex) - [List-Extra.findIndex: elm](hhttps://package.elm-lang.org/packages/elm-community/list-extra/7.1.0/List-Extra#findIndex) - [_.findIndex: lodash](https://lodash.com/docs/4.17.15#findIndex) - [Array.findIndex: sugarjs](https://sugarjs.com/docs/#/Array/findIndex) [:running:]: https://npm.runkit.com/@extra-array/find-index [:package:]: https://www.npmjs.com/package/@extra-array/find-index [:moon:]: https://www.npmjs.com/package/@extra-array/find-index.min [:ledger:]: https://unpkg.com/@extra-array/find-index/ [findIndex]: https://github.com/nodef/extra-array/wiki/findIndex [findIndices]: https://github.com/nodef/extra-array/wiki/findIndices [find]: https://github.com/nodef/extra-array/wiki/find [:vhs:]: https://asciinema.org/a/332048