I have two arrays
var a = [4,8,9,7];
var b = [1,5,7,3,9];
I want result
[4,8,1,5,3]
I have tried using filter-
function diffArray(arr1, arr2) {
var newArr = [];
var newArr2 = [];
newArr = arr1.filter(function(e) {
return arr2.indexOf(e) < 0;
});
newArr2 = arr2.filter(function(e) {
return arr1.indexOf(e) < 0;
});
var arr = newArr.concat(newArr2);
return arr;
}
Is there any better way to get the same result.