The Parameters
Zero-based index at which to start extraction. A negative index can be used, indicating an offset from the end of the sequence. If If end Optional The index of the first element to exclude from the returned array. A negative index can be used, indicating an offset from the end of the sequence. If If Return valueA new array containing the extracted elements. DescriptionThe
The ExamplesReturn a portion of an existing array
Using slice In the following example,
This script writes: myCar = [ { color: 'red', wheels: 4, engine: { cylinders: 4, size: 2.2 } }, 2, 'cherry condition', 'purchased 1997' ] newCar = [{color: 'red', wheels: 4, engine: {cylinders: 4, size: 2.2}}, 2] myCar[0].color = red newCar[0].color = red The new color of my Honda is purple myCar[0].color = purple newCar[0].color = purple Array-like objects
Binding can be done with the
Anyway, it can be simplified using
Using slice() on sparse arraysThe array returned from
Specifications
Browser compatibilityBCD tables only load in the browser See also |