How to remove a particular element from an array in javascript?

In this article, We’ll see how to remove a particular element from an array in javascript?




let’s create a employee‘s array as follows:

  let employee = ["Peter", "Alex", "Holding", "Mark", "Smith", "John", "Alex", "Holding"];
  console.log(employee); // Output ["Peter", "Alex", "Holding", "Mark", "Smith", "John", "Alex", "Holding"]

if we want to remove the value “Alex” from an employee’s array. what will do ?

We can use filter method to remove the value “Alex” from an array.

    let deleteValue  = "Alex";
    employee = employee.filter(item => item !== deleteValue)
    console.log(employee); // Output  ["Peter", "Holding", "Mark", "Smith", "John", "Holding"]

That’s it!. Please share your thoughts or suggestions in the comments below.

Leave a Reply

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