VOOZH about

URL: https://www.geeksforgeeks.org/javascript/javascript-delete-first-occurence-of-given-element-from-a-js-array/

⇱ JavaScript - Delete First Occurence of Given Element from a JS Array - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

JavaScript - Delete First Occurence of Given Element from a JS Array

Last Updated : 23 Jul, 2025

These are the following ways to delete elements from a specified Index of JavaScript arrays:

1. Using indexOf() and splice() - Most Used

The indexOf() method finds the first occurrence of the element in the array, and splice() removes it at that index. This approach directly modifies the original array.


Output
[ 1, 2, 4, 3, 5 ]

2. Using filter() method

The filter() method is used to create a new array that excludes the first occurrence of the element, without modifying the original array.


Output
[ 1, 2, 4, 3, 5 ]

3. Using findIndex() with splice()

The findIndex() method returns the first occurrence of the element matching the condition, if it exists the splice() method is used to remove the element.


Output
[ 1, 2, 4, 3, 5 ]

4. Using for loop

The for loop manually iterates over the elements of the array to find and delete the first occurrence. The loop is stopped immediately after deleting the element.


Output
[ 1, 2, 4, 3, 5 ]
Comment