Get to know MDN better
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The slice() method of Array instances returns a shallow copy of a portion of an array into a new array object selected from start to end (end not included) where start and end represent the index of items in that array. The original array will not be modified.
Zero-based index at which to start extraction, converted to an integer.
Zero-based index at which to end extraction, converted to an integer. slice() extracts up to but not including end.
A new array containing the extracted elements.
The slice() method is a copying method. It does not alter this but instead returns a shallow copy that contains some of the same elements as the ones from the original array.
The slice() method preserves empty slots. If the sliced portion is sparse, the returned array is sparse as well.
The slice() method is generic. It only expects the this value to have a length property and integer-keyed properties.
In this example, slice(1, 3) extracts elements from index 1 up to, but not including, index 3, resulting in a new array ['Orange', 'Lemon'].
In this example, slice(2) extracts elements from index 2 to the end of the array.
In this example, slice(-2) extracts the last two elements of the array. When using a negative index with the slice method, negative indices are counted from the end of the array, starting at -1 for the last element, -2 for the second-to-last element, and so on. The negative index -2 itself is included because it is the starting point of the extraction.
| | | | | | | S | L | I | C | E | | | | | | | -5 -4 -3 -2 -1 <--- read from reverseIn this example, slice(1, -1) starts extracting from index 1 and goes up to, but does not include, the element at index -1 (which is the last element). This results in a new array with ['Banana', 'Orange', 'Mango']. The slice method always excludes the element at the final index specified, regardless of whether it is positive or negative.
read from start ---> 0 1 2 3 4 | | | | | | | S | L | I | C | E | | | | | | | -5 -4 -3 -2 -1 <--- read from reverseIn the following example, slice creates a new array, newCar, from myCar. Both include a reference to the object myHonda. When the color of myHonda is changed to purple, both arrays reflect the change.
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 = purpleThe slice() method reads the length property of this. It then reads the integer-keyed properties from start to end and defines them on a newly created array.
The slice() method is often used with bind() and call() to create a utility method that converts an array-like object into an array.
The array returned from slice() may be sparse if the source is sparse.
| ECMAScript® 2027 Language Specification # sec-array.prototype.slice |
Enable JavaScript to view this browser compatibility table.
This page was last modified on Jul 20, 2025 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.