javascript - Is there a method in angularjs similar to removeall in java?
PHP中文网
PHP中文网 2017-05-19 10:40:45
0
1
676

In java, if I have a list A and a list B, I want to remove all the B elements in A.
You can A.removeALL(B)
But this method is not recognized in angularjs. So I'm a little confused. I can't find a similar method on the Internet. Can I just write a method by myself? Or is there any other method that is equivalent to removeall?

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(1)
过去多啦不再A梦

It’s like this, the method A.removeALL(B) is not a method of angularjs, nor is it a method of native js. It is not a method that exists in java.
It is actually very simple to implement such a method using native js.
Apprentice I wrote a js by hand, as follows:

function removeAll(array){
    const _this = this;
    array.forEach(function(v) {
        const i = _this.indexOf(v);
        i >= 0 && _this.splice(i, 1);
    });
}
let a = [1,2,3,4,5,6,7,8,9,10];
let b = [1,3,5,7,9];
removeAll.call(a,b);
console.log(a); // [2, 4, 6, 8, 10]
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template