Javascript Set Merge two array to get unique element

Description

Javascript Set Merge two array to get unique element

function uniqueList(arr1, arr2) {
    var mySet = new Set(arr1.concat(arr2));
    return Array.from(mySet);
}
let a = uniqueList([1,1,2,2],[2,3,4,5]); // [1,2,3,4,5]
console.log(a);//from   www .j  ava2  s . c om

a = uniqueList([1,2],[3,4,5]); // [1,2,3,4,5]
console.log(a);

a = uniqueList([],[2,2,3,4,5]); // [2,3,4,5]
console.log(a);



PreviousNext

Related