Removing an element from a given position of the array in Javascript

Front End TechnologyJavascriptWeb Development

Sometimes you need to remove an element from a given position in an array. JavaScript gives the splice method to remove from a given index. It can be used as follows −

Example

let veggies = ["Onion", "Raddish", "Broccoli"];
veggies.splice(0, 1); // Removes 1 element from index 0
console.log(veggies);

Output

This will give the output −

["Raddish", "Broccoli"]
raja
Published on 26-Jun-2018 14:03:44
Advertisements