How do I remove a particular element from an array in JavaScript?

How do I remove a particular element from an array in JavaScript? I have an array of numbers array = [5,9,5,10]; , and I'm using the .pop() method to remove elements from it. but only last element from array is removing..
Deepak Sharma
Asked 24-09-2021
63

Answer (1)
this your solution use indexOf() and array.splice() method in javascript.  var array = [2, 5, 9]; console.log(array); var index = array.indexOf(5); if (index > -1) {   array.splice(index, 1); } // array = [2, 9] alert(array);
Ankur Rajput
Asked 29-01-2020
45 Likes
Comments
Write comment

Submit your answer