Discuss / JavaScript / ....

GodKeen粉

#1 Created at ... [Delete] [Delete and Lock User]

var list = document.getElementById('test-list');

var filterWords = ['JavaScript','HTML','CSS'];

for(let j = 0;j < list.children.length;j++){  

    //都可以

    /*if(filterWords.findIndex(function (x){

        return x === list.children[j].innerText;

    }) === -1){    

        list.removeChild(list.children[j]);

        j--;

    }*/

    if(!filterWords.includes(list.children[j].innerText)){

        list.removeChild(list.children[j]);

        j--;

    }

}


  • 1

Reply