Computer >> Computer tutorials >  >> Programming >> Javascript

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


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"]