JavaScript (ES2026) reference · Array Methods
JavaScript Array slice() Method
Return a shallow copy of part of the array, from start up to (not including) end. The original is not changed.
JavaScript (ES2026) Since ES3
Syntax
array.slice(start, end)
Parameters
| Parameter | Description |
|---|---|
start optional |
Start index; negative counts from the end. Default: 0 |
end optional |
End index (not included). Default: array.length |
Return value
A new array.
Examples
const letters = ["a", "b", "c", "d", "e"];
console.log(letters.slice(1, 3), letters.slice(-2), letters.slice());
Output
[ 'b', 'c' ] [ 'd', 'e' ] [ 'a', 'b', 'c', 'd', 'e' ]
const items = [1, 2, 3];
const copy = items.slice();
copy.push(4);
console.log(items, copy);
Output
[ 1, 2, 3 ] [ 1, 2, 3, 4 ]
Don't confuse slice() (copies, doesn't change the array) with splice() (changes the array in place).
Version history
| Version | Change |
|---|---|
| JavaScript ES3 | Added |
Related
array.splice()· Remove, replace or insert elements at a position, changing the array in place. Returns the removed elements.array.toSpliced()· Return a new array with elements removed, replaced or inserted at a position, leaving the original unchanged.array.at()· Return the element at an index, where negative indexes count from the end: arr.at(-1) is the last element.- JavaScript Arrays · tutorial