Skip to content

searchValue

Subhajit Sahu edited this page May 3, 2023 · 14 revisions

Find first index of a value.

Alternatives: searchValue, searchValueRight, searchValueAll.
Similar: search, scan, find.


function searchValue(x, v, fc, fm)
// x:  an array
// v:  search value
// fc: compare function (a, b)
// fm: map function (v, i, x)
const xarray = require('extra-array');

var x = [1, 2, 3, 2, 5];
xarray.searchValue(x, 2);
// → 1      ^

var x = [1, -2, 3, 2, 5];
xarray.searchValue(x, 2, (a, b) => Math.abs(a) - Math.abs(b));
// → 1       ^

var x = [1, -2, 3, 2, 5];
xarray.searchValue(x, 2, null, v => Math.abs(v));
// → 1       ^


References

Clone this wiki locally