🌐
W3Schools
w3schools.com › jsref › jsref_splice.asp
W3Schools.com
JS Arrays · Array[ ] Array( ) at() concat() constructor copyWithin() entries() every() fill() filter() find() findIndex() findLast() findLastIndex() flat() flatMap() forEach() from() includes() indexOf() isArray() join() keys() lastIndexOf() length map() of() pop() prototype push() reduce() reduceRight() rest (...) reverse() shift() slice() some() sort() splice() spread (...) toReversed() toSorted() toSpliced() toString() unshift() values() valueOf() with() JS Boolean ·
🌐
W3Schools
w3schools.com › js › tryit.asp
W3Schools online HTML editor
The W3Schools online code editor allows you to edit code and view the result in your browser
🌐
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 Blog
w3schools.blog › home › javascript array splice()
JavaScript Array splice() - W3schools
April 20, 2019 - <!DOCTYPE html> <html> <body> <script> var a = ["GOLD","SILVER","DIAMOND","RUBY","PLATINUM"] var result=a.splice(2,1,"BRONZE") document.writeln(a); </script> </body> </html>
🌐
W3Schools
w3schools.sinsixx.com › jsref › jsref_splice.asp.htm
JavaScript splice() Method - SinSiXX - W3Schools
Free HTML XHTML CSS JavaScript DHTML XML DOM XSL XSLT RSS AJAX ASP ADO PHP SQL tutorials, references, examples for web building.
🌐
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 - In this tutorial, you will learn how you can remove, add, or replace elements of an array using the splice() method.
🌐
IQCode
iqcode.com › code › javascript › what-is-splice-in-javascript
what is splice in javascript Code Example
Sign up · Develop soft skills on BrainApps Complete the IQ Test ... what is the use of array splice in javascript what does array splice return array splice injs javascript array splice w3schools how to splice an array element in javascript arry.splice javascript sslice splice injs arr splice js splice in loop javascript splice(i 1) javascript to splice array.splicer splice() mdn splice define array.splice javacsript javascript array splice element javascript splice on , splice method in javascript splice in arr js splice with , what splice in javascript can you splice an array splice array m
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]

Find elsewhere
🌐
Cach3
w3schools.com.cach3.com › jsref › jsref_splice.asp.html
JavaScript Array splice() Method - W3Schools
cssText getPropertyPriority() getPropertyValue() item() length parentRule removeProperty() setProperty() JS Conversion ... var fruits = ["Banana", "Orange", "Apple", "Mango"]; fruits.splice(2, 0, "Lemon", "Kiwi"); Try it Yourself »
🌐
Medium
medium.com › @ryan_forrester_ › javascripts-splice-method-a-complete-guide-c579ff14af7a
JavaScript’s splice() Method: A Complete Guide | by ryan | Medium
November 19, 2024 - JavaScript’s splice() Method: A Complete Guide Breakdown of splice in JavaScript The splice() method is one of JavaScript’s most useful array manipulation tools. Unlike simpler methods that only …
🌐
Refine
refine.dev › home › blog › tutorials › how to use javascript array splice
How to Use JavaScript Array Splice | Refine
September 5, 2024 - In particular, we observe how to wipe out items from a certain index onward. We also go through examples of replacing existing items with new ones. We explore how to insert items in the case of overloaded replacement and injection. We also figure out splice() way of adding items to the tail of the array.
🌐
W3Schools
w3schools.invisionzone.com › browser scripting › javascript
Help with Javascript splice - JavaScript - W3Schools Forum
February 20, 2008 - hey guys. I need some help.I'm working on a script where it randomizes an array of elements that are checked. I'm using input boxes, and depending on what which input box is checked, is the array that gets randomized. For example purposes, I shortened my script to the problem area.This is what I'...
🌐
GeeksforGeeks
geeksforgeeks.org › javascript-array-splice-method
JavaScript Array splice() Method - GeeksforGeeks
The splice() method can be used to remove elements from an array.
Published   May 24, 2025
🌐
Mimo
mimo.org › glossary › javascript › splice
JavaScript Splice Method: Array Modification Techniques
Edit arrays in place with JavaScript splice, add or remove items, and see syntax and examples.
🌐
To The New
tothenew.com › home › javascript : array.splice() vs array.slice()
JavaScript Array.splice() vs Array.slice() | TO THE NEW Blog
November 29, 2016 - Told you, we love sharing · 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
🌐
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.
🌐
W3Schools
w3schools.com › js › tryjs_array_splice.htm
W3schools
The splice() method adds new elements to an array: