how to add an index to every other index in the array in javascript code example
Example: javascript every other element in array
let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
// filter out all elements that are located at an even index in the array.
let x = arr.filter((element, index) => {
return index % 2 === 0;
})
console.log(x)
// [1, 3, 5, 7, 9]