Array.slice() Slice a sub-array
Last updated: 2026-09-09
Array.slice() Slice a sub-array
slice extracts a shallow-copied section (start inclusive, end exclusive) with negative indices supported. The original is fully untouched — the bedrock of immutable array ops.
| Category | Arrays |
|---|---|
| ES version | ES3 (1999) |
📝 Syntax
const newArray = array.slice(start, end);
⚙️ Parameters
| start | Optional. Start index (inclusive); negative counts from the end; default 0. |
|---|---|
| end | Optional. End index (exclusive); negative counts from the end; default is the end. |
Returns:A new shallow-copied array.
Mutates the original:No (returns a new value)
▶ Example
Edit the code, press Run, and see the result in the output panel:
Output:
[ 'banana', 'orange' ]
[ 'orange', 'grape', 'melon' ]
[ 'grape', 'melon' ]
false
💡 Tip slice() with no args is the shortest array copy; it is shallow — object elements share references.
ℹ️ info Negative-index rules match String.slice — learn once, use twice.
🌐 Browser support
| Browser | |||||
|---|---|---|---|---|---|
| Array.slice() | ✓ v1 | ✓ v12 | ✓ v1.5 | ✓ v3 | ✓ v10.5 |
| Supported by all modern browsers | |||||
🏷️ Related Array Methods
💡 Related Cases
More case studies coming soon — check back later.
📚 Related Tutorials
❓ FAQ
Qslice vs splice?
Aslice copies; splice mutates — the 'p' in splice means powerful.
QDoes slice(1, 3) include index 3?
ANo — end is exclusive. Omit end to slice to the end.
QIs slice a deep copy?
AShallow — nested objects share references. Use structuredClone(arr) for deep copies.