Skip to content

indexOf

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

Find first index of a value.

Alternatives: indexOf, lastIndexOf.
Similar: search, indexOf, isValue, includes.


function indexOf(x, v, i)
// x: an array
// v: search value
// i: begin index [0]
const xarray = require('extra-array');

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

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


References

Clone this wiki locally