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

🌐
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.
🌐
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 ...
🌐
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.
🌐
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
Find elsewhere
🌐
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>"); });
🌐
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.
🌐
Refine
refine.dev › home › blog › tutorials › how to use javascript array splice
How to Use JavaScript Array Splice | Refine
September 5, 2024 - Use the method splice() when you want to alter an array by removing, inserting, or replacing elements and use the method slice() when you want to retrieve a part of the array without having to change the array.
🌐
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
🌐
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].

🌐
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 slice( ) method copies a given part of an array and returns that copied part as a new array. It doesn’t change the original array. ... For example, I want to slice the first three elements from the array above.
🌐
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 - That's why javascript methods can be confused each other sometimes. Split is a function that split the given string into an array of substrings. The split method doesn't change the original string array and will return the new array.
🌐
Sophiali
sophiali.dev › javascript-slice-splice
Remembering slice vs splice in JavaScript
And there we have it! This blog goes over the differences between slice and splice. You now know that slice makes a shallow copy of the original array, while splice mutates the original array and optionally adds or removes 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)); ...
🌐
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.