Filter and delete filtered elements in an array

前端 未结 6 1490
遥遥无期
遥遥无期 2020-12-09 16:32

I want to remove specific elements in the original array (which is var a). I filter() that array and splice() returned new array. but

6条回答
  •  佛祖请我去吃肉
    2020-12-09 17:33

    You can assign filter array to a itself and then apply splice over it.

    Example below:

    var a = [{name:'tc_001'}, {name:'tc_002'}, {name:'tc_003'}]
    a = a.filter(function (e) {
        return e.name === 'tc_001';
    });
    
    a.splice(0,1);
    

提交回复
热议问题