How do I remove an element in a list, using forEach?

前端 未结 4 677
抹茶落季
抹茶落季 2020-12-03 09:38
var people = [\'alex\',\'jason\',\'matt\'];

people.forEach(function(p){
    if(p.length > 4){
       //REMOVE THIS PERSON or pop it out of the list or whatever
          


        
4条回答
  •  渐次进展
    2020-12-03 10:14

    ForEach, since ES5 can be used together with an index:

    data.forEach(function (element, index) {
      if (element % 2 == 0) {
        data.splice(index, 1);
      }
    });
    

提交回复
热议问题