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

Get zero-based index for an element in array.

Similar: index, indexRange, size, isEmpty.


function index(x, i)
// x: an array
// i: ±index
const xarray = require('extra-array');

var x = [2, 4, 6, 8];
xarray.index(x, 1);
// → 1

xarray.index(x, -1);
// → 3

xarray.index(x, -10);
// → 0


References

Clone this wiki locally