Skip to content
Subhajit Sahu edited this page Nov 20, 2022 · 17 revisions

Get zero-based index for element in array.

Similar: index, indexRange, size, isEmpty.


function index(x, i)
// x: an array
// i: index (-ve: from right)
const array = require('extra-array');

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

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

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


References

Clone this wiki locally