burger
0
Q:

array remove index from array

const array = [2, 5, 9];

//Get index of the number 5
const index = array.indexOf(5);
//Only splice if the index exists
if (index > -1) {
  //Splice the array
  array.splice(index, 1);
}

//array = [2, 9]
console.log(array); 
3
// remove element at certain index without changing original
let arr = [0,1,2,3,4,5]
let newArr = [...arr]
newArr.splice(1,1)//remove 1 element from index 1
console.log(arr) // [0,1,2,3,4,5]
console.log(newArr)// [0,2,3,4,5]
10

New to Communities?

Join the community