@extra-array/search-value
v2.10.19
Published
Finds first index of a value.
Downloads
54
Maintainers
Readme
Finds first index of a value. :package: :smiley_cat: :running: :vhs: :moon: :scroll: :newspaper: :blue_book:
Alternatives: searchValue, searchValueRight, searchValueAll. Similar: search, scan, find.
This is part of package extra-array.
array.searchValue(x, v, [fc], [fm]);
// x: an array
// v: search value
// fc: compare function (a, b)
// fm: map function (v, i, x)
// → index of value, -1 if not found
const array = require("extra-array");
var x = [1, 2, 3, 2, 5];
array.searchValue(x, 2);
// 1 ^
var x = [1, -2, 3, 2, 5];
array.searchValue(x, 2, (a, b) => Math.abs(a) - Math.abs(b));
// 1 ^
var x = [1, -2, 3, 2, 5];
array.searchValue(x, 2, null, v => Math.abs(v));
// 1 ^