JavaScript Array splice() method17 Mar 2025 | 2 min read The JavaScript array splice() method is used to add/remove the elements to/from the existing array. It returns the removed elements from an array. The splice() method also modifies the original array. SyntaxThe splice() method is represented by the following syntax: Parameterstart - It represents the index from where the method start to extract the elements. delete - It is optional. It represents the number of elements to be removed. element1,element2,...,elementn - It is optional. It represent the elements to be inserted. ReturnA new array containing the removed elements. JavaScript Array splice() method exampleHere, we will understand splice() method through various examples. Example 1Let's see an example to add an element to the existing array without removing other elements. Test it NowOutput: Monday,Tuesday,Wednesday,Thursday,Friday Example 2Let's see an example to add an element to the existing array while removing other elements. Test it NowOutput: Updated array: Monday,Tuesday,Wednesday,Thursday,Friday Removed element: Saturday,Sunday Example 3Let's see an example to add two elements to the existing array while removing one element. Test it NowOutput: Updated array: Monday,Tuesday,Wednesday,Thursday,Friday Removed element: Sunday Example 4Let's see an example to remove the elements from the existing array. Test it NowOutput: Updated array: Monday,Tuesday Removed element: Saturday,Sunday,Thursday,Friday Next TopicJavaScript Array |
JavaScript Array Method The method creates a new array iterator object that carries the values specified at each array index. We can iterate the array elements via loops or iterator methods. Syntax array.; Parameter It does not hold any parameter as such. Return It creates and returns a newly created...
2 min read
JavaScript Array method The JavaScript array method filter and extract the element of an array that satisfying the provided condition. It doesn't change the original array. Syntax The method is represented by the following syntax: array.filter(callback(currentvalue,index,arr),thisArg) Parameter callback - It represents the function that test the condition. currentvalue -...
1 min read
JavaScript Array method The JavaScript array method fills the elements of the given array with the specified static values. This method modifies the original array. It returns undefined, if no element satisfies the condition. Syntax The method is represented by the following syntax: arr.fill(value[, start[, end]]) Parameter value...
1 min read
JavaScript Array method The JavaScript array method removes the first element of the given array and returns that element. This method changes the length of the original array. Syntax The method is represented by the following syntax: array. Return The first element of an array. JavaScript Array ...
1 min read
JavaScript Array Method The method creates and returns a new iterator object which holds the key for every index in the array. This method does not affect the original array. Syntax array.; Parameter It does not hold any parameter. Return It returns a new array iterator object. JavaScript Array Example Let's...
2 min read
JavaScript Array Method The method creates a string that represents the elements of an array. It converts the array elements into the string. Syntax array.; Parameter array: It is the given array or the source array. Including this, there are two optional parameters also. locales: It is a string that...
2 min read
JavaScript Array method The JavaScript array method adds one or more elements in the beginning of the given array and returns the updated array. This method changes the length of the original array. Syntax The method is represented by the following syntax: array. unshift(element1,element2,....,elementn) Parameter element1,element2,....,elementn - The...
1 min read
JavaScript Array Method The method creates and returns a new array from different a number of arguments. It does not focus on the type and number of arguments. Similar to Array, it also provides a constructor that handles the integer arguments, but in a...
2 min read
JavaScript Array Method The method is a combination of flat() and map() methods. This method initially maps each array element through a mapping function, then flatten up the array with depth value as 1. Syntax var newArr=arr.flatMap(function callback(currentValue[ , index[ , array]]) { return element } [ , thisArg]) Parameters callback-...
2 min read
JavaScript Array Method The method creates a new iterator object of an array, holding the key/value pairs for every value in the array. A key represents the index number carrying an item as its value. It does not affect the original array. Syntax The following syntax...
2 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India