Answers for "js when remove array list itme one by using loop the last element not find"

11

javascript removing items looping through array

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"]
Posted by: Guest on August-02-2019

Code answers related to "js when remove array list itme one by using loop the last element not find"

Code answers related to "Javascript"

Browse Popular Code Answers by Language