remove index of array code example
Example 1: javascript remove from array by index
array.splice(index, 1);
Example 2: array remove index from array
const array = [2, 5, 9];
const index = array.indexOf(5);
if (index > -1) {
array.splice(index, 1);
}
console.log(array);
Example 3: js array delete specific element
var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
var removed = arr.splice(2,2);
Example 4: js delete all from array
var list = [1, 2, 3, 4];
function empty() {
list.length = 0;
}
empty();
Example 5: how to delete an element from an array in javascript
["bar", "baz", "foo", "qux"]list.splice(0, 2)