JavaScript ambil hanya indeks array bahkan
for (var i = 0; i < a.length; i++) {
if(i % 2 === 0) { // index is even
ar.push(a[i]);
}
}
Horrible Herring
for (var i = 0; i < a.length; i++) {
if(i % 2 === 0) { // index is even
ar.push(a[i]);
}
}
for(var i = 0; i < a.length; i += 2) { // take every second element
ar.push(a[i]);
}