First of all i check a lot of post, like this:
Finding matches between multiple JavaScript Arrays
How to merge two arrays in Javascript and de-duplicate items
All these works fine but only with arrays that contain integers or strings, i need that works for whatever you want.
i have two arrays, and want to storage in a new array the unique elements, and in other array the common elements. These elements could be; variables, arrays, strings, hash (objects) functions, integers, float numbers or boolean
And probably never gonna be a duplicate value inside of the arrays. Would be awesome with plain JS
And i don't care about IE (but would be nice for others i guess), so if there is a new ES6 way, i gonna love it , i care more about performance :)
// Some values that gonna be inside the array1 & array2
function random(){};
var a = 5,
b = {};
// The Arrays
var array1 = [0,1,2,3, "HeLLo", "hello", 55.32, 55.550, {key: "value", keyWithArray: [1,2,3]}, random, a, b];
var array2 = [2,3, "hello", "Hello", 55.32, 55.551, {key: "value", keyWithArray: [1,2,3]}, b];
// The Unique Array should be all the elements that array1 have and array2 haven't
var uniqueArray = [0, 1, "HeLLo", 55.550, random, a];
// The commonArray should the common elements in both arrays (array1 and array2)
var commonArray = [2,3, "hello", 55.32, {key: "value", keyWithArray: [1,2,3]}, b]
// I try something like this but doesn't work
var uniqueArray = array1.filter(function(val) { return array2.indexOf(val) == -1; });
console.log(uniqueArray);