1const array = [2, 5, 9];
2
3//Get index of the number 5
4const index = array.indexOf(5);
5//Only splice if the index exists
6if (index > -1) {
7 //Splice the array
8 array.splice(index, 1);
9}
10
11//array = [2, 9]
12console.log(array);
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]