fruits = ["mango","apple","pine","berry"];
If I want to remove an element index wise, How to do that using JavaScript. Also you can use library as required.
You can use splice
to do the same. Syntax = array.splice(start_index, no_of_elements)
Following is the command:
const fruits = ["mango","apple","pine","berry"]; // returns mutated array
const removed = fruits.splice(2, 1); // returns array of removed items
console.log('fruits', fruits);
console.log('removed', removed);
This will remove one element from index 2, i.e. after the operation fruits=["mango","apple","berry"];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With