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);

Answer from Thalaivar on Stack Overflow
🌐
W3Schools
w3schools.com › jsref › jsref_splice.asp
JavaScript Array splice() Method
The splice() method adds and/or removes array elements. The splice() method overwrites the original array. The Array toSpliced() Method · The Array slice() Method · array.splice(index, count, item1, ....., itemX) // Create an Array const fruits ...
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › what-is-the-difference-between-array-slice-and-array-splice-in-javascript
What is the difference between Array.slice() and Array.splice() in JavaScript ? - GeeksforGeeks
July 12, 2025 - `slice()` creates a new array containing selected elements from the original, while `splice()` modifies the original array by adding, removing, or replacing elements. The slice() method in JavaScript extracts a section of an array and returns ...
People also ask

What is the main difference between slice and splice in JavaScript?
The main difference is that slice() creates a new array with a portion of elements copied from the original array, while splice() mutates the original array itself by removing, replacing or adding elements to it.
🌐
simplilearn.com
simplilearn.com › home › resources › software development › slice vs splice: know the key differences [2024]
Slice vs Splice: Know the Key Differences [2024]
Can splice be used to add new elements to an array?
Yes, splice() can be used to add new elements by specifying the new elements as additional arguments after the deleteCount parameter. For example: let fruits = ['apple', 'mango']; fruits.splice(1, 0, 'orange'); // insert orange at index 1  // fruits is now ['apple', 'orange', 'mango']
🌐
simplilearn.com
simplilearn.com › home › resources › software development › slice vs splice: know the key differences [2024]
Slice vs Splice: Know the Key Differences [2024]
Does the slice modify the original array?
No, slice() does not modify the original array. It returns a shallow copy of selected elements from the original array into a new array without changing the original.
🌐
simplilearn.com
simplilearn.com › home › resources › software development › slice vs splice: know the key differences [2024]
Slice vs Splice: Know the Key Differences [2024]
🌐
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. To create a new array with a segment removed and/or replaced without mutating the original array, use toSpliced(). To access part of an array ...
🌐
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 - ... Unlike the slice() method, the splice() method will change the contents of the original array. The splice() method is used to add or remove elements of an existing array and the return value will be the removed items from the array.
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]

🌐
Medium
medium.com › @avinashkumar151199 › slice-and-splice-in-javascript-30e81e4ea997
Slice and Splice in JavaScript?. slice()-: Slice is used to get a new… | by Avinash Kumar | Medium
August 10, 2023 - In a.slice(0, 8) means that you ... portion is ['Apple', 'Pine-Apple']. splice()-: Splice is used to add/remove an element from the given array, it change the original array....
🌐
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.
Find elsewhere
🌐
Dasha
dasha.ai › blog › javascript-arrays-slice-and-splice
Dasha | Slice and Splice JavaScript Arrays Like a Pro
December 7, 2021 - The array slice javascript method copies a chunk (or slice) from an array and returns that copied part as a new array. It does not modify or change the original array. Instead, it creates a new shallow copy of the original array.
🌐
Joel Olawanle
joelolawanle.com › blog › slice-vs-splice-javascript-understanding-differences-use
Slice vs. splice in JavaScript: Understanding the differences and when to use them | Joel Olawanle
April 9, 2023 - By understanding the differences and knowing when to use each method, you'll be able to create new arrays, modify existing ones, and slice and dice your way to JavaScript success! Try what you have learned in the interactive code editor below. const fruits = ['apple', 'banana', 'orange', 'kiwi', 'mango']; fruits.splice(2, 1, 'grape', 'pear'); fruits.forEach((value) => { document.write(value + "<br>"); });
🌐
Simplilearn
simplilearn.com › home › resources › software development › slice vs splice: know the key differences [2024]
Slice vs Splice: Know the Key Differences [2024]
February 21, 2024 - Confused about JavaScript's slice & splice? Our guide clarifies differences & uses with practical examples. Elevate your coding skills by mastering these methods!
Address   5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
🌐
Medium
medium.com › @stevenpaulino1 › javascript-methods-slice-and-splice-29048a88a54f
Javascript methods: Slice() and Splice() | by Steven Paulino | Medium
January 7, 2019 - Just give me whatever is between these 2 indexes! Very similar naming like slice and what sometimes confuses me. Splicing changes arrays by adding and removing elements. array.splice(x); // Every element starting from index x, will be removed
🌐
DEV Community
dev.to › codepumps › what-is-the-difference-splice-slice-and-split-method-in-javascript-3mll
What is the difference splice, slice, and split method in Javascript ? - DEV Community
November 5, 2020 - It is method of both arrays and strings. Slice method can take two arguments. First argument is required, second argument is optional. First argument that represent where to start selection. Second argument that represent where to end selection. Splice method changes the original array.
🌐
Refine
refine.dev › home › blog › tutorials › how to use javascript array splice
How to Use JavaScript Array Splice | Refine
September 5, 2024 - Slice in JavaScriptsplice()slice()Key Differences:Splice on Multidimensional ArraysModifying the Outer ArrayChanging Inner ArraysInserting ElementsApplication ExampleKey PointsUsing Splice with Destructuring in JavaScriptBasic Splice + DestructuringExample: Element SwappingExtracting Multiple Elements with DestructuringDestructuring + InsertionWhy Use This?Summary
🌐
YoungWonks
youngwonks.com › blog › slice-vs-splice
What is the difference between slice and splice? Does splice mean split? How to remove array elements by using splice?
April 15, 2024 - You can learn more about the slice ... In contrast, the splice method, also known as javascript array splice, is used to modify the contents of an array by removing existing elements and/or adding new elements....
🌐
freeCodeCamp
freecodecamp.org › news › lets-clear-up-the-confusion-around-the-slice-splice-split-methods-in-javascript-8ba3266c29ae
Let’s clear up the confusion around the slice( ), splice( ), & split( ) methods in JavaScript
October 9, 2018 - The name of this function is very similar to slice( ). This naming similarity often confuses developers. The splice( ) method changes an array, by adding or removing elements from it. Let’s see how to add and remove elements with splice( ): For removing elements, we need to give the index parameter, and the number of elements to be removed:
🌐
Reddit
reddit.com › r/learnjavascript › splice and slice in javascript
r/learnjavascript on Reddit: SPLICE and SLICE in JavaScript
June 26, 2022 -

SPLICE:

-splice() changes the original array and returns an array object

example-
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].

SLICE:

-slice() doesn’t change the original array and returns an array object

example -
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].

🌐
Scaler
scaler.com › topics › slice-and-splice-in-javascript
slice vs. splice in JavaScript - Scaler Topics
February 6, 2024 - Key differences include slice() returning a new array and being non-destructive, while splice() directly alters the original array and returns an array containing the removed elements.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › String › slice
String.prototype.slice() - JavaScript | MDN
The slice() method of String values extracts a section of this string and returns it as a new string, without modifying the original string. const str = "The quick brown fox jumps over the lazy dog."; console.log(str.slice(31)); // Expected output: "the lazy dog." console.log(str.slice(4, 19)); ...