Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

get odd elements of list javascript

list = [1, 2, 3, 4, 5, 6, 7]
for (var i = 0; i < table.length; i++) {
    if(i % 2 === 0 ) { // index is even
        odd_elements.push(list[i]);
    }
}
console.log(odd_elements)j
>> [2, 4, 6]
 
PREVIOUS NEXT
Tagged: #odd #elements #list #javascript
ADD COMMENT
Topic
Name
2+5 =