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

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

array.slice(start, end)

Parameters

ParameterDescription
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

Take part of an arrayTry it yourself
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' ]
Copy an arrayTry it yourself
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

VersionChange
JavaScript ES3Added

In other languages

Was this page helpful?