JavaScript Array splice() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Array

Definition

Array.prototype.splice(start, deleteCount?, ...items) changes an array in place: remove, insert, or replace elements at any index. It returns an array of removed items (often empty). Need a copy without mutation? Use slice() or toSpliced().

Remember
array.splice(start, deleteCount, item1, item2, …)

remove:  splice(1, 2)
insert:  splice(1, 0, "x", "y")
replace: splice(1, 2, "x", "y")

returns → array of removed items
mutates the original array ✓

slice  = copy (safe)
splice = edit in place

Syntax

Call array.splice. Start with this line.

JavaScript
array.splice(start, deleteCount?, …items)
CallWhat it does
array.splice(start, deleteCount?, …items)Primary signature.
array.splice(...)Call with the arguments your case needs.

Built into JavaScript. Call splice(...) on an array instance — no import required.

Library declarations
JavaScript
array.splice(start, deleteCount?, …items)

Parameters

ParameterDescription
startRequired. Index where changes begin
deleteCountOptional. How many to remove; omit to delete through the end
...itemsOptional. Values to insert at start

Return Value

Return ValueDescription
*Array of removed items (not the array itself)

JavaScript Examples

Example 1 — Remove Elements

Delete two items starting at index 1 and capture what was removed.

JavaScript
const fruits = ["apple", "banana", "orange", "kiwi"];

const removed = fruits.splice(1, 2);

console.log("removed:", removed);
// ["banana", "orange"]
console.log("fruits:", fruits);
// ["apple", "kiwi"]
Try It Yourself

How It Works

  1. Start at index 1. That is "banana".
  2. Delete two. deleteCount 2 removes "banana" and "orange".
  3. Return value. removed holds those deleted items.
  4. Array updated. fruits becomes ["apple", "kiwi"] in place.

Example 2 — Insert Without Removing

Set deleteCount to 0 to insert only.

JavaScript
const fruits = ["apple", "kiwi"];

fruits.splice(1, 0, "pineapple", "peach");

console.log(fruits);
// ["apple", "pineapple", "peach", "kiwi"]
Try It Yourself

How It Works

  1. Zero deletions. Nothing is removed from the array.
  2. Insert at index 1. "pineapple" and "peach" go in before "kiwi".
  3. Shift right. Existing items after the insert point move over.
  4. Return value. An empty array [] — nothing was deleted.

Example 3 — Replace Elements

Remove two items and insert two different ones in the same spot.

JavaScript
const fruits = ["apple", "banana", "orange", "kiwi"];

fruits.splice(1, 2, "grape", "melon");

console.log(fruits);
// ["apple", "grape", "melon", "kiwi"]
Try It Yourself

How It Works

  1. Remove first. Drop "banana" and "orange" at index 1.
  2. Insert next. Place "grape" and "melon" in that gap.
  3. One call. Replace is remove + insert together.
  4. Ends stay. "apple" and "kiwi" keep their roles at the edges.

Browser & Runtime Support

Array.prototype.splice() has been part of JavaScript since ES3. It is available everywhere arrays are.

✓ Baseline · ES3

Array.prototype.splice()

Supported in every major browser (including Internet Explorer) and all Node.js versions. No polyfill required.

100% Universal support
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
Array.splice() Excellent

Bottom line: Safe everywhere. For immutable middle-of-array edits in modern engines, prefer toSpliced() (ES2023) when you cannot mutate the source.

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() when you only need a copy, or toSpliced() (ES2023) for a non-mutating splice-like result.
An array of the removed elements. If nothing was removed, you get []. The modified array is the same reference you called splice on—not the return value.
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.

Next: toLocaleString()

Learn how to format array elements as a locale-aware string.

toLocaleString() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful