remove value from javascript array code example
Example 1: remove item from array javascript
const array = [2, 5, 9];
console.log(array);
const index = array.indexOf(5);
if (index > -1) {
array.splice(index, 1);
}
console.log(array);
Example 2: remove a value from array js
const index = array.indexOf(item);
if (index > -1) {
array.splice(index, 1);
}
Example 3: remove a value to an array of javascript
var data = [1, 2, 3];
data.splice(1, 1);
data.pop();
Example 4: how to delete an element from an array in javascript
var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];var removed = arr.splice(2,2);