Skip to content
Subhajit Sahu edited this page May 3, 2023 · 23 revisions

Find first value passing a test.

Alternatives: find, findRight, findAll.
Similar: search, scan, find.


function find(x, ft)
// x:  an array
// ft: test function (v, i, x)
const xarray = require('extra-array');

var x = [1, 2, 3, 4, 5];
xarray.find(x, v => v % 2 == 0);
// → 2      ^

xarray.find(x, v => v % 2 == 1);
// → 1   ^


References

Clone this wiki locally