Home  >  Q&A  >  body text

javascript - Is there a method in angularjs similar to removeall in java?

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中文网2710 days ago641

reply all(1)I'll reply

  • 过去多啦不再A梦

    过去多啦不再A梦2017-05-19 10:42:45

    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]

    reply
    0
  • Cancelreply