javascript grab only even array index

Solutions on MaxInterview for javascript grab only even array index by the best coders in the world

showing results for - "javascript grab only even array index"
Santino
21 Jan 2021
1for (var i = 0; i < a.length; i++) {
2    if(i % 2 === 0) { // index is even
3        ar.push(a[i]);
4    }
5}
6
Mía
09 May 2016
1for(var i = 0; i < a.length; i += 2) {  // take every second element
2    ar.push(a[i]);
3}
4