1const index = array.indexOf(item);
2if (index !== -1) array.splice(index, 1);
1const index = array.indexOf(item);
2if (index > -1) {
3 array.splice(index, 1);
4}
1// remove 5
2let arr = [1,2,3,4,5,6];
3let remove = arr.filter((id) => id !== 5)
4console.log(remove) // [1,2,3,4,6]
1var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
2var removed = arr.splice(2,2);
3/*
4removed === [3, 4]
5arr === [1, 2, 5, 6, 7, 8, 9, 0]
6*/
1// remove element at certain index without changing original
2let arr = [0,1,2,3,4,5]
3let newArr = [...arr]
4newArr.splice(1,1)//remove 1 element from index 1
5console.log(arr) // [0,1,2,3,4,5]
6console.log(newArr)// [0,2,3,4,5]