How to get the union of two arrays in Node.js

1 Answer

0 votes
const arr1 = ['node.js', 'c++', 'c'];
const arr2 = ['node.js', 'c', 'c#', 'python'];

const union = Array.from(new Set([...arr1, ...arr2]));

console.log(union);


    
     
     
     
/*
run:
     
[ 'node.js', 'c++', 'c', 'c#', 'python' ]
     
*/

 



answered Jun 24, 2022 by avibootz

Related questions

1 answer 111 views
1 answer 72 views
3 answers 200 views
1 answer 123 views
1 answer 99 views
1 answer 204 views
...