Use slice() to copy a portion of an array without changing it; use splice() to remove, insert, or replace elements in the original array. The easiest way to keep them straight is to check whether you want a new selection or an in-place edit.
How slice() and splice() differ
| Method | Changes the original array? | Arguments | Returns | Use it to |
|---|---|---|---|---|
slice(start, end) |
No | Start and end positions; the end position is excluded | A new shallow array containing the selected elements | Copy or read a portion of an array |
splice(start, deleteCount, ...items) |
Yes | Start position, number of elements to remove, and optional items to insert | An array of the removed elements | Edit an array in place |
toSpliced(start, skipCount, ...items) |
No | Start position, number of elements to remove, and optional items to insert | A new array with the edit applied | Make a splice-like edit without changing the original |
The similar names can be misleading, so focus on the effects: slice() selects; splice() changes. This is a mnemonic for these methods, not a general rule for every JavaScript method with a similar name.
As an Amazon Associate I earn from qualifying purchases.
What slice() does
slice() returns selected elements in a new array and leaves the source array unchanged. In slice(start, end), end is an index position, not a number of items to take, and that position is excluded.
Free tools Windows power users keep installed
One-click scans. No signup required.
const colors = ["red", "green", "blue", "purple"];
const middle = colors.slice(1, 3);
// middle: ["green", "blue"]
// colors: ["red", "green", "blue", "purple"]
The call starts at index 1 and stops before index 3, so it includes indexes 1 and 2.
#1 Best Overall
Slice() index behavior
- With no arguments,
slice()returns a shallow copy of the whole array. - If
endis omitted orundefined, the selection continues to the end. - Negative indexes count backward from the end. A start before the beginning is treated as zero; a start at or beyond the array length produces an empty array.
- If the normalized end position is at or before the normalized start position, the result is empty.
What splice() does
splice() edits the array it is called on. Its second argument is a removal count, unlike the end-position argument in slice(). Any values after that count are inserted at the starting position. The method returns the removed elements, not the edited array.
const colors = ["red", "green", "blue", "purple"];
const removed = colors.splice(1, 2, "gold");
// removed: ["green", "blue"]
// colors: ["red", "gold", "purple"]
Here, splice(1, 2, "gold") starts at index 1, removes two items, then inserts "gold" at that position.
Rank #2
Splice() argument behavior
splice(start)with only a start position removes from that position through the end.splice()with no arguments removes nothing.splice(start, 0, item)inserts an item without deleting anything.- A start position beyond the array length inserts at the end. Negative starts count back from the end and are clamped at the beginning.
- If no elements are removed, the return value is an empty array.
Because the return value contains deleted elements, assigning it to a variable does not save the edited source array. Also, do not infer splice()‘s return behavior from push(): push() returns the array’s new length.
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →Does slice() make an independent copy?
It makes a new array, but the copy is shallow. Primitive values are copied as values; for objects, the new array and the original hold references to the same objects. Changing an object through one reference is therefore visible through the other.
const original = [{ name: "Ari" }];
const copy = original.slice();
copy[0].name = "Sam";
// original[0].name is also "Sam"
The arrays are separate containers, but slice() does not recursively clone the objects inside them.
How to edit immutably with toSpliced()
If you want the remove-and-insert behavior of splice() but need to keep the original array unchanged, use toSpliced() where the runtime supports it. It returns a new edited array; the original still contains its previous elements. Unlike splice(), it does not return the removed elements separately. MDN marks toSpliced() as widely available since July 2023.
Rank #4
const months = ["Jan", "March", "April"];
const updated = months.toSpliced(1, 1, "Feb");
// updated: ["Jan", "Feb", "April"]
// months: ["Jan", "March", "April"]
For the behavior described by MDN, see the slice(), splice(), toSpliced(), and Array references on MDN Web Docs, accessed October 7, 2026.
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Repair Windows errors before they cause bigger problems3Scan for outdated or missing drivers - takes under a minuteQuick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




