Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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]
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #javascript #element #array
ADD COMMENT
Topic
Name
2+6 =