Answers for "js array remove multiple elements by index"

11

javascript remove multiple items from 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
0

js remove several elements from array

var ar = [1, 2, 3, 4, 5, 6];ar.pop(); // returns 6console.log( ar ); // [1, 2, 3, 4, 5]
Posted by: Guest on July-10-2020

Code answers related to "js array remove multiple elements by index"

Code answers related to "Javascript"

Browse Popular Code Answers by Language