JavaScript - Delete First Occurence of Given Element from a JS Array Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report These are the following ways to delete elements from a specified Index of JavaScript arrays:1. Using indexOf() and splice() - Most UsedThe 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. JavaScript let a = [1, 2, 3, 4, 3, 5]; // Element to be deleted let x = 3; let i = a.indexOf(x); if (i !== -1) { a.splice(i, 1); } console.log(a); Output[ 1, 2, 4, 3, 5 ] 2. Using filter() methodThe filter() method is used to create a new array that excludes the first occurrence of the element, without modifying the original array. JavaScript let a1 = [1, 2, 3, 4, 3, 5]; let x = 3; let found = false; let a2 = a1.filter(value => { if (value === x && !found) { found = true; return false; // Skip first match } return true; // Include all other elements }); console.log(a2); 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. JavaScript let a = [1, 2, 3, 4, 3, 5]; let x = 3; let i = a.findIndex(value => value === x); if (i !== -1) { a.splice(i, 1); } console.log(a); Output[ 1, 2, 4, 3, 5 ] 4. Using for loopThe 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. JavaScript let a = [1, 2, 3, 4, 3, 5]; let x = 3; for (let i = 0; i < a.length; i++) { if (a[i] === x) { a.splice(i, 1); break; } } console.log(a); Output[ 1, 2, 4, 3, 5 ] Comment More info A amit_singh27 Follow Improve Article Tags : JavaScript Web Technologies javascript-array Explore JavaScript BasicsIntroduction to JavaScript4 min readVariables and Datatypes in JavaScript6 min readJavaScript Operators5 min readControl Statements in JavaScript4 min readArray & StringJavaScript Arrays7 min readJavaScript Array Methods7 min readJavaScript Strings6 min readJavaScript String Methods9 min readFunction & ObjectFunctions in JavaScript5 min readJavaScript Function Expression3 min readFunction Overloading in JavaScript4 min readObjects in Javascript4 min readJavaScript Object Constructors4 min readOOPObject Oriented Programming in JavaScript3 min readClasses and Objects in JavaScript4 min readWhat Are Access Modifiers In JavaScript ?5 min readJavaScript Constructor Method7 min readAsynchronous JavaScriptAsynchronous JavaScript2 min readJavaScript Callbacks4 min readJavaScript Promise4 min readEvent Loop in JavaScript4 min readAsync and Await in JavaScript2 min readException HandlingJavascript Error and Exceptional Handling6 min readJavaScript Errors Throw and Try to Catch2 min readHow to create custom errors in JavaScript ?2 min readJavaScript TypeError - Invalid Array.prototype.sort argument1 min readDOMHTML DOM (Document Object Model)9 min readHow to select DOM Elements in JavaScript ?3 min readJavaScript Custom Events4 min readJavaScript addEventListener() with Examples9 min readAdvanced TopicsClosure in JavaScript4 min readJavaScript Hoisting6 min readJavascript Scope3 min readJavaScript Higher Order Functions7 min readDebugging in JavaScript4 min read Like