In this post we are going to see how to compare two array elements? and do something, when the element is matched. This below prototype method will do that trick. Array.prototype.diff = function(arr2) { this.sort(); arr2.sort(); for(var i = 0; i < this.length; i += 1) { if(arr2.indexOf( this[i] ) > -1){ arr2.splice(arr2.indexOf( this[i] ), 1); } …