📜  获取列表javascript代码示例的奇数元素

📅  最后修改于: 2022-03-11 15:01:22.346000             🧑  作者: Mango

代码示例1
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]