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

Get part of an array!

Alternatives: slice, slice$.


function slice$(x, i, I)
// x: an array (updated!)
// i: begin index [0]
// I: end index [|x|]
const xarray = require('extra-array');

var x = [1, 2, 3, 4, 5];
xarray.slice$(x, 2);
// → [ 3, 4, 5 ]

x;
// → [ 3, 4, 5 ]

var x = [1, 2, 3, 4, 5];
xarray.slice$(x, 2, 4);
// → [ 3, 4 ]

var x = [1, 2, 3, 4, 5];
xarray.slice$(x, -3, -1);
// → [ 3, 4 ]


References

Clone this wiki locally