The splice() method is the Swiss Army knife for in-place array edits: remove, insert, or replace elements at any index. It returns the removed items. This tutorial covers syntax, return values, and how it differs from slice().
01
Syntax
splice(i, n, ...)
02
Remove
deleteCount > 0
03
Insert
deleteCount = 0
04
Replace
Remove + add
05
Returns
Removed []
06
vs slice
Mutates
Fundamentals
Introduction
Need to delete two items from the middle, drop in three new ones, or swap a section of an array? splice() does all of that in one call. Unlike slice(), which copies a range without touching the original, splice()mutates the array you call it on.
It also returns a new array of whatever was removed—handy when you need to undo, log, or process deleted items.
Concept
Understanding the splice() Method
array.splice(start, deleteCount, item1, item2, ...) begins at start (negative values count from the end), removes deleteCount elements, then inserts any extra arguments at that position.
Omitting deleteCount removes everything from start to the end. Setting deleteCount to 0 inserts without removing.
💡
Beginner Tip
Remember the name pair: slice = copy a slice (safe). splice = splice in changes (mutates). One letter difference, very different behavior.
Negative start counts from the end (-1 = last index). For end-only removal, pop() is simpler; splice shines at any index.
Applications
🚀 Common Use Cases
Delete from middle — remove a todo at index 3.
Insert in middle — add item without rebuilding array.
Replace block — swap a run of elements.
Trim tail — arr.splice(5) drops from index 5 onward.
Undo buffer — store return value before re-inserting.
React state — prefer immutable patterns; copy then splice if needed.
🧠 How splice() Runs
1
Resolve start
Negative? Count from array length.
Index
2
Remove deleteCount
Collect removed elements into return array.
Delete
3
Insert new items
Shift elements right to make room.
Insert
4
✅
Return removed
Original array is already updated.
Important
📝 Notes
Mutates the original array.
Returns removed elements, not the updated array.
deleteCount = 0 inserts without deleting.
Omitting deleteCount removes through end of array.
Negative start is supported (counts from end).
Do not confuse with slice() (non-mutating copy).
ES2023: toSpliced() returns a new array without mutating.
Compatibility
Browser & Runtime Support
Array.prototype.splice() has been available since ES3 and is supported in every browser and Node.js environment.
✓ Baseline · ES3
Array.prototype.splice()
Supported everywhere: Chrome, Firefox, Safari, Edge, IE, and all Node.js versions. Non-mutating toSpliced() requires ES2023 (2023+ browsers).
100%Universal support
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.jsSupported · Server runtime
Supported
Android WebViewSupported · Modern WebView
Full support
Array.splice()Excellent
Bottom line: One of the oldest, most reliable array methods. Safe in any JavaScript environment.
Wrap Up
Conclusion
splice() is the go-to method for in-place array surgery: remove, insert, or replace at any index. Remember it returns what was removed, mutates the original, and pairs conceptually with non-mutating slice().
Next, learn toLocaleString() to format array values for display.
Overuse splice in React—spread + filter is often clearer
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about Array.splice()
Edit arrays in place at any index.
5
Core concepts
📝01
Syntax
splice(i, n, ...)
API
🗑02
Remove
deleteCount > 0.
Delete
➕03
Insert
deleteCount = 0.
Add
📦04
Returns
Removed [].
Return
⇄05
vs slice
Mutates.
Compare
❓ Frequently Asked Questions
splice() changes an array in place by removing, inserting, or replacing elements starting at a given index. It returns a new array containing the removed elements (which may be empty).
Yes. splice() modifies the original array. Use slice() or toSpliced() (ES2023) when you need a non-mutating alternative.
An array of the removed elements. If nothing was removed, you get an empty array []. The modified array is the same reference you called splice on.
Set deleteCount to 0: arr.splice(index, 0, newItem1, newItem2). Elements shift right to make room at index.
slice(start, end) extracts a copy without mutating. splice(start, deleteCount, ...items) removes/inserts in the original array and returns removed items. Similar names, opposite immutability.
splice() has been available since ES3 and works in all browsers including very old environments and every Node.js version.
Did you know?
Many developers first learn slice() and splice() together because the names differ by one letter—but slice copies safely while splice mutates. That single-letter trap causes real bugs in production code.