0 points

javascript - How can I find matching values in two arrays? - Stack Overflow


dashboard

Sat Aug 15 2020 03:32:07 GMT+0000 (UTC)

Posted by @rdemo #javascript

Array.prototype.diff = function(arr2) {
    var ret = [];
    this.sort();
    arr2.sort();
    for(var i = 0; i < this.length; i += 1) {
        if(arr2.indexOf(this[i]) > -1){
            ret.push(this[i]);
        }
    }
    return ret;
};
content_copy Copy

https://stackoverflow.com/questions/12433604/how-can-i-find-matching-values-in-two-arrays