What is the difference between Array.slice() and Array.splice() in JavaScript ? Last Updated : 28 May, 2024 Comments Improve Suggest changes Like Article Like Report In JavaScript, slice() and splice() are array methods with distinct purposes. `slice()` creates a new array containing selected elements from the original, while `splice()` modifies the original array by adding, removing, or replacing elements. slice():The slice() method in JavaScript extracts a section of an array and returns a new array containing the selected elements, without modifying the original array. Syntax: array_name.slice(s, e)Example: In this example The slice() method in JavaScript extracts elements from the cars array, creating a new array new_cars from index 1 up to, but not including, index 4. JavaScript let cars = ['Benz', 'Innova', 'Breeza', 'Etios', 'Dzire']; let new_cars = cars.slice(1, 4); console.log("cars :", cars); console.log("new_cars :", new_cars); Outputcars : [ 'Benz', 'Innova', 'Breeza', 'Etios', 'Dzire' ] new_cars : [ 'Innova', 'Breeza', 'Etios' ] splice():The splice() method in JavaScript is used to change the contents of an array by removing or replacing existing elements and/or adding new elements in place, modifying the original array. Syntax: array_name.splice(i, n, item 1, item 2, .....item n) Example: In this example, The splice() method in JavaScript inserts new elements ('ambassador', 'BMW', 'Audi') into the cars array at index 2 without removing any elements. javascript let cars = ['Benz', 'Innova', 'Breeza', 'Etios', 'Dzire']; cars.splice(2, 0, 'ambassedor', 'BMW', 'Audi'); console.log("cars :", cars); Outputcars : [ 'Benz', 'Innova', 'ambassedor', 'BMW', 'Audi', 'Breeza', 'Etios', 'Dzire' ] Difference Table between Array.slice() and Array.splice()slice()splice()This method is used to get a new array by selecting a sub-array of a given array. This method is used to add/remove an item from the given array. The parameter 's' indicates the starting index and 'e' indicates the ending index. They denote the index of the sub-array to be taken. By default, the value for start is '0' and end is 'n'.The parameter 'i' denotes the starting index, 'n' denotes the number of items to be removed from the specified starting index.'item 1, item 2, .....item n' represents the list of new items to be added at the given index. If n=0, no item is removed, the new items are just added to the specified starting index.The changes do not reflect in the original array.The changes are reflected in the original arrayThe result has to be assigned to a new array variable.The result need not be assigned to any other new variable.The return value is a new array with the values in the selected sub-array of the given array. The values in the range start to (end-1) will be selected.The return value is an array containing the deleted element.Takes exactly 2 argumentsTakes 'n' number of arguments (a list of new items can be supplied) Comment More infoAdvertise with us Next Article What is the difference between Array.slice() and Array.splice() in JavaScript ? E erakshaya485 Follow Improve Article Tags : Technical Scripter JavaScript Web Technologies Technical Scripter 2019 PHP-function +1 More Similar Reads Difference between Array and Array of Objects in JavaScript ArrayAn Array is a collection of data and a data structure that is stored in a sequence of memory locations. One can access the elements of an array by calling the index number such as 0, 1, 2, 3, ..., etc. The array can store data types like Integer, Float, String, and Boolean all the primitive dat 3 min read Difference Between Array.from and Array.of in JavaScript JavaScript provides various methods for creating and manipulating arrays, two of which are Array.from and Array.of. These methods are part of the ECMAScript 6 (ES6) specification and offer distinct ways to create arrays. Understanding the differences between these two methods is important for effici 3 min read What is the difference between every() and some() methods in JavaScript ? In this article, we will see the difference between every() and some() methods in JavaScript. Array.every() methodThe Array.every() method in JavaScript is used to check whether all the elements of the array satisfy the given condition or not. The output will be false if even one value does not sati 3 min read What is the difference between unshift() and Push() method in JavaScript? JavaScript Unshift() method is very much similar to the push() method but the difference is that the unshift() method adds the elements at the very beginning of the array whereas the push() method adds at the end of the array. Javascript Array unshift() method: The JavaScript Array unshift() Method 2 min read Difference between String.slice and String.substring in JavaScript These 2 functions are quite similar in their Syntax But are different in some cases. Let's see the difference between them. JavaScript slice() Method:This method selects the part of a string and returns the selected part as a new string. Start and end parameters are used to specify the extracted par 3 min read Different Ways to Use Array Slice in JavaScript In this article, we will see the different ways to use the Array slice method in Javascript. Using Array Slice in JavaScript refers to the technique of extracting a specified portion of an array, defined by start and end indices, to create a new array containing those selected elements. Syntaxarr.sl 4 min read Difference between substr() and substring() in JavaScript In JavaScript Both of the functions are used to get the specified part of the string, But there is a slight difference between them. substr() and substring() are string methods used to extract parts of a string. The main difference is that substr() accepts a length parameter, while substring() accep 2 min read What are the different operations can be performed with a JavaScript Array? In this article, we are going to learn different operations that can be performed with an Array by using JavaScript, An array in JavaScript is a data structure that holds an ordered collection of values, which can be of any data type, using zero-based indexing for access and manipulation, including 5 min read Difference between forEach() and map() loop in JavaScript The forEach() and map() methods in JavaScript are used to iterate over arrays, but they serve different purposes. forEach() executes a provided function once for each array element without returning a new array, while map() transforms elements and returns a new array.JavaScript forEach() JavaScript' 4 min read JavaScript - Insert Elements at a Given Position in an JS Array To insert an element at a specific position in a JavaScript array, the JS splice() method is used. JavaScriptlet a = [10, 20, 30, 40]; let e = 50; let i = 2; a.splice(i - 1, 0, e); console.log(a);Output[ 10, 50, 20, 30, 40 ] Table of ContentUsing built-in MethodWriting Your Own MethodUsing built-in 1 min read Like