📌  相关文章
📜  javascript 在循环中从数组中删除项目 - Javascript 代码示例

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

代码示例1
var colors=["red","green","blue","yellow"];
//loop back-words through array when removing items like so:
for (var i = colors.length - 1; i >= 0; i--) {
    if (colors[i] === "green" || colors[i] === "blue") { 
        colors.splice(i, 1);
    }
}
//colors is now  ["red", "yellow"]