๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ JavaScript โ€บ Reference โ€บ Global_Objects โ€บ Array โ€บ splice
Array.prototype.splice() - JavaScript | MDN
The splice() method of Array instances changes the contents of an array by removing or replacing existing elements and/or adding new elements in place.
๐ŸŒ
W3Schools
w3schools.com โ€บ jsref โ€บ jsref_splice.asp
W3Schools.com
The splice() method adds and/or removes array elements.
Discussions

Splice function on an array of objects
I'm doing a react/javascript exercice and i'm having some trouble understanding the use of splice() in it. I have 8 cards, and i need to randomly assign 4 cards to 2 players. Now everything works ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
A better way to splice an array into an array in javascript - Stack Overflow
The answers above that involve splice.apply and insert the array in a one liner will blow up the stack in a stack overflow for large array. See example here: http://jsfiddle.net/gkohen/u49ku99q/ You might have to slice and and push each item of the inserted and remaining part of the original ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
JavaScript Array splice vs slice - Stack Overflow
When you have a sandwich, what you really do is have two splices, not two slices. You will have reduced the loaf by doing so. Unintuitive, I know. ... This will return [3,4,5]. The original array is affected resulting in array being [1,2]. More on stackoverflow.com
๐ŸŒ stackoverflow.com
Is array.splice(0, array.length) the only way to empty a reactive array in vue 3?
I always use ref, then you can do array.value = []. More on reddit.com
๐ŸŒ r/vuejs
18
1
November 17, 2022
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ javascript โ€บ javascript-array-splice-method
JavaScript Array splice() Method - GeeksforGeeks
JS Tutorial ยท Web Tutorial ยท ... 16 Jan, 2026 ยท The splice() method in JavaScript is used to change the contents of an array by removing, replacing, or adding elements....
Published ย  January 16, 2026
๐ŸŒ
p5.js
p5js.org โ€บ reference โ€บ p5 โ€บ splice
splice
Reverses the order of an array, maps to Array.reverse() . Looking for the new version? Find p5.js 2.0 here!
๐ŸŒ
Refine
refine.dev โ€บ home โ€บ blog โ€บ tutorials โ€บ how to use javascript array splice
How to Use JavaScript Array Splice | Refine
September 5, 2024 - And passing the items list depends on whether/what we want to insert or add to the array. It is also possible to pass all arguments at the same time. In the coming sections, we consider most of the cases. As we'll start seeing next, splice() mutates the original array and returns an array containing removed items.
๐ŸŒ
Metana
metana.io โ€บ metana: coding bootcamp | software, web3 & cyber โ€บ full-stack โ€บ javascript array splice() method - metana
JavaScript Array Splice() Method - Metana
November 10, 2024 - You can even use negative values to count backward from the end of the array. deleteCount (Optional): This specifies the number of elements you want to remove starting from the startIndex. If omitted, no elements are removed. item1, item2, โ€ฆ itemN (Optional): These are the new elements you want to insert at the startIndex. Any number of items can be added here. Important Note: splice() modifies the original array directly.
๐ŸŒ
DhiWise
dhiwise.com โ€บ post โ€บ javascript-array-splice-method-a-detailed-exploration
JavaScript Array Splice Method: A Comprehensive Guide
September 5, 2024 - The item1, item2,... are the new elements to be added to the array. The JavaScript splice method can be used to remove elements from an array. The number of elements removed depends on the second argument passed to the splice method.
Find elsewhere
๐ŸŒ
Codementor
codementor.io โ€บ blog โ€บ javascript splice: what is javascript splice and what can it do?
JavaScript Splice: What is JavaScript Splice and What Can It Do?
June 21, 2022 - The JavaScript splice() method is a built-in method for JavaScript array functions. Splice modifies the original array by removing, replacing, or adding elements. The return value is a new array containing the deleted elements.
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ javascript-slice-and-splice-how-to-use-the-slice-and-splice-js-array-methods
How to Use the slice() and splice() JavaScript Array Methods
April 13, 2022 - If nothing was removed from the array, then the return value will just be an empty array. Here is the basic syntax. splice(start, optional delete count, optional items to add)
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ home โ€บ javascript โ€บ javascript array splice method
JavaScript Array Splice Method
September 1, 2008 - Learn how to use the JavaScript Array splice() method to add or remove elements from an array. Explore examples and syntax for effective coding.
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ javascript-splice-how-to-use-the-splice-js-array-method
JavaScript Splice โ€“ How to Use the .splice() JS Array Method
April 23, 2021 - It lets you change the content of your array by removing or replacing existing elements with new ones. This method modifies the original array and returns the removed elements as...
๐ŸŒ
DEV Community
dev.to โ€บ rfornal โ€บ javascript-array-splice-issue-5301
JavaScript Array Splice Issue - DEV Community
September 17, 2019 - When dealing with removing an item from the array, I generally like to do an immutable version for the reason described above in the post. So instead of ยท const arr = ['one', 'two', 'three', 'four', 'five']; arr.splice(arr.indexOf(name), 1);
๐ŸŒ
Mimo
mimo.org โ€บ glossary โ€บ javascript โ€บ splice
JavaScript Splice Method: Array Modification Techniques
It directly changes the original array. ... Become a full-stack developer. Learn HTML, CSS, JavaScript, and React as well as NodeJS, Express, and SQL ... Master the language of the web. Learn variables, functions, objects, and modern ES6+ features ... const months = ['Jan', 'March', 'April', 'June']; months.splice(1, 2); // Removes 2 elements starting from index 1 // Result: months is now ['Jan', 'June']
๐ŸŒ
JavaScript Tutorial
javascripttutorial.net โ€บ home โ€บ javascript array methods โ€บ array.prototype.splice()
JavaScript Array splice(): Delete, Insert, and Replace Elements
November 6, 2024 - [ 'red', 'yellow', 'pink', 'green', 'blue' ]Code language: JSON / JSON with Comments (json) The splice() method lets you insert new elements into an array while simultaneously deleting existing elements.
๐ŸŒ
Educative
educative.io โ€บ answers โ€บ splice-vs-slice-in-javascript
splice vs. slice in JavaScript
slice returns a piece of the array but it doesnโ€™t affect the original array. splice changes the original array by removing, replacing, or adding values and returns the affected values.
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 56378540 โ€บ splice-function-on-an-array-of-objects
Splice function on an array of objects
Its just a way to get the removed element of the array. hand2.splice(randIndex, 1) will return the removed elements from array.
๐ŸŒ
CodingNomads
codingnomads.com โ€บ javascript-array-splice-insert-delete-replace
How to Replace, Add or Delete Array Items: JavaScript Splice
Discover how to use JavaScript's .splice() method for array manipulation, including adding, removing, and replacing elements in arrays
Top answer
1 of 16
433

splice() changes the original array whereas slice() doesn't but both of them returns array object.

See the examples below:

var array=[1,2,3,4,5];
console.log(array.splice(2));

This will return [3,4,5]. The original array is affected resulting in array being [1,2].

var array=[1,2,3,4,5]
console.log(array.slice(2));

This will return [3,4,5]. The original array is NOT affected with resulting in array being [1,2,3,4,5].

Below is simple fiddle which confirms this:

//splice
var array=[1,2,3,4,5];
console.log(array.splice(2));

//slice
var array2=[1,2,3,4,5]
console.log(array2.slice(2));


console.log("----after-----");
console.log(array);
console.log(array2);

2 of 16
130

Splice and Slice both are Javascript Array functions.

Splice vs Slice

  1. The splice() method returns the removed item(s) in an array and slice() method returns the selected element(s) in an array, as a new array object.

  2. The splice() method changes the original array and slice() method doesnโ€™t change the original array.

  3. The splice() method can take n number of arguments and slice() method takes 2 arguments.

Splice with Example

Argument 1: Index, Required. An integer that specifies at what position to add /remove items, Use negative values to specify the position from the end of the array.

Argument 2: Optional. The number of items to be removed. If set to 0(zero), no items will be removed. And if not passed, all item(s) from provided index will be removed.

Argument 3โ€ฆn: Optional. The new item(s) to be added to the array.

var array=[1,2,3,4,5];
console.log(array.splice(2));
// shows [3, 4, 5], returned removed item(s) as a new array object.
 
console.log(array);
// shows [1, 2], original array altered.
 
var array2=[6,7,8,9,0];
console.log(array2.splice(2,1));
// shows [8]
 
console.log(array2.splice(2,0));
//shows [] , as no item(s) removed.
 
console.log(array2);
// shows [6,7,9,0]

Slice with Example

Argument 1: Required. An integer that specifies where to start the selection (The first element has an index of 0). Use negative numbers to select from the end of an array.

Argument 2: Optional. An integer that specifies where to end the selection but does not include. If omitted, all elements from the start position and to the end of the array will be selected. Use negative numbers to select from the end of an array.

var array=[1,2,3,4,5]
console.log(array.slice(2));
// shows [3, 4, 5], returned selected element(s).
 
console.log(array.slice(-2));
// shows [4, 5], returned selected element(s).
console.log(array);
// shows [1, 2, 3, 4, 5], original array remains intact.
 
var array2=[6,7,8,9,0];
console.log(array2.slice(2,4));
// shows [8, 9]
 
console.log(array2.slice(-2,4));
// shows [9]
 
console.log(array2.slice(-3,-1));
// shows [8, 9]
 
console.log(array2);
// shows [6, 7, 8, 9, 0]

๐ŸŒ
Dustin John Pfister
dustinpfister.github.io โ€บ 2021 โ€บ 07 โ€บ 20 โ€บ js-array-splice
The array splice method for removing an injecting elements in an array | Dustin John Pfister at github pages
July 20, 2021 - First off if I just want to remove one or more elements from an array, and do not care if I am mutating the array in place the process of using the array splice method is fairly simple. I just call the array splice method off of the instance of the array that I want to mutate and give an array index as the first argument.