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 118 views
1 answer 78 views
3 answers 211 views
1 answer 130 views
1 answer 108 views
1 answer 224 views
...