remove array value in javascript code example
Example 1: remove a value from array js
const index = array.indexOf(item);
if (index > -1) {
array.splice(index, 1);
}
Example 2: delete from array based on value javascript
var index = array.indexOf(item);
if (index !== -1) array.splice(index, 1);
Example 3: how to remove item from array javascript
var array = ["Item", "Item", "Delete me!", "Item"]
array.splice(2,1)
Example 4: remove elements from array js
const array = [2, 5, 9];
console.log(array);
const index = array.indexOf(5);
if (index > -1) {
array.splice(index, 1);
}
console.log(array);
Example 5: remove a value to an array of javascript
var data = [1, 2, 3];
data.splice(1, 1);
data.pop();
Example 6: remove element from array javascript
let numbers = [1,2,3,4]
let last_num = numbers.pop();
let first_num = numbers.shift();
let number_index = 1
let index_num = numbers.splice(number_index,1);