How to intersect two arrays and eliminate their equal values?

1

I have two different arrays in jQuery:

a = {1, 5, 3, 4}
b = {1, 4}

First obtain the intercepted values, they would be 1 , 4 . Then delete the intercepted values in the a array, it would look like this:

a = {5, 3}

Any ideas?

    
asked by elizabeth 20.04.2016 в 23:11
source

1 answer

3

Considering the comment of @ César, the arrangements do not use braces but brackets.

You can use filter , pure JavaScript, example:

var a = [1, 5, 3, 4],
    b = [1, 4]

var result = a.filter(function(e) {
    return b.indexOf(e) == -1
});

console.log(result);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    
answered by 20.04.2016 / 23:36
source