javascript grab only even array index code example
Example 1: javascript grab only even array index
for(var i = 0; i < a.length; i += 2) { // take every second element
ar.push(a[i]);
}
Example 2: javascript grab only even array index
for (var i = 0; i < a.length; i++) {
if(i % 2 === 0) { // index is even
ar.push(a[i]);
}
}