Remove a specific item from an array in javascript
unknown
javascript
3 years ago
248 B
6
Indexable
const array = [1, 7, 9];
console.log(array);
const index = array.indexOf(7);
if (index > -1) { // only splice array when item is found
array.splice(index, 1); // 2nd parameter means remove one item only
}
// array = [1, 9]
console.log(array); Editor is loading...