Finds index of leftmost value passing a test.
Alternatives: findIndex, findIndices.
Similar: find, findIndex.
This is part of package extra-array.
array.findIndex(x, fn);
// x: an array
// fn: test function (v, i, x)
// --> index of value, -1 if not found
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
- List-Extra.findIndex: elm
- _.findIndex: lodash
- Array.findIndex: sugarjs