how to remove value from array code example
Example 1: remove a value from array js
const index = array.indexOf(item);
if (index > -1) {
array.splice(index, 1);
}
Example 2: js array delete specific element
var array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
var filtered = array.filter(function(value, index, arr){
return value > 5;
});
Example 3: how to remove item from array in 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 4: remove a value to an array of javascript
var data = [1, 2, 3];
data.splice(1, 1);
data.pop();
Example 5: how can i remove a specific item from an array
const items = ['a', 'b', 'c', 'd', 'e', 'f']
const i = 2
const filteredItems = items.slice(0, i).concat(items.slice(i + 1, items.length))
Example 6: how to remove a variable from an array javascript
let colors = ["red","blue","car","green"];
colors.splice(color[2]);