var array1 = ['a', 'c','d','f','h'];
var array2 = ['a','b', 'c','d','e','f','g','h'];
document.write('array 1 : '+array1+'<br>');
document.write('array 2 : '+array2+'<br>');
//prototype method for array to find and remove matched element from argument array.
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);
}
}
};
//code usage for above prototype method.
array1.diff(array2);
document.write('result array : '+array2);
//Note : I have used document.write() method to just show the out put in screen. But using document.write() is not recommended.