Answers for "javascript grab only even array index"

0

javascript grab only even array index

for(var i = 0; i < a.length; i += 2) {  // take every second element
    ar.push(a[i]);
}
Posted by: Guest on April-27-2021
0

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]);
    }
}
Posted by: Guest on April-27-2021

Code answers related to "javascript grab only even array index"

Code answers related to "Javascript"

Browse Popular Code Answers by Language