How to Remove Multiple Elements From Array in Javascript

Last Updated on April 17, 2024 by Roshan Parihar

To remove multiple elements from an array in javascript, use the for loop with splice() function.

The multiple elements can be a small part of the array to remove from it. The filter() function can also be useful to delete many items from an array.

Let’s find out with the examples given below.

Using splice() in Loop to Remove Multiple Element from Array in Javascript

If you want to remove multiple elements of an array in javascript, you can use the for loop inside which gets the index position of each element. After that, you can use the splice() function to remove the element according to its index position.

Examples 1


The multiple specified elements to remove from an array are [13, 7, 17]. When you click the button given above, these elements get removed from the given array. You can check the output to see the result of the method.

Remove with For Loop with filter() Function of Javascript

It uses the loop to filter out the multiple elements from the array using the filter(). In each loop, the specified array element gets removed.

Example 2


Two elements are [21, 3] to delete from the given array using javascript. When you click the button above, it will give you the output of the new array without the elements [21, 3].

Delete With Javascript filter() and includes() Function

In addition to the above examples, you can also use the filter() function with the includes() function in javascript as given below. It does not require to use of a loop to perform the deletion of the multiple array element.

Examples 3


The elements to remove from the given array are [9, 7, 17]. You can click the button given above to remove multiple array elements. The output contains the array of items with removed multiple items.

You May Also Like to Read

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.