📌  相关文章
📜  获取数组中的所有其他项目 - Javascript 代码示例

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

代码示例3
// If you want every odd index value:
var myArray = ["First", "Second", "Third", "Fourth", "Fifth"]
function every_other(array){
    var temporaryArray = []
    for (var i = 0; i < array.length; i += 2){ //Add two to i every iteration
        temporaryArray.push(array[i]) //Add the element at index i to a temporary array
    }
    return temporaryArray.join(", ")
}
console.log(every_other(myArray)) //Expected output: First, Third, Fifth