How to get the union of two arrays in TypeScript

1 Answer

0 votes
const arr1 = ['typescript', 'c++', 'c'];
const arr2 = ['typescript', 'c', 'c#', 'php'];

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

console.log(union);


    
     
     
     
/*
run:
     
["typescript", "c++", "c", "c#", "php"] 
     
*/

 



answered Jun 24, 2022 by avibootz

Related questions

1 answer 103 views
1 answer 119 views
1 answer 100 views
1 answer 103 views
103 views asked Oct 24, 2021 by avibootz
1 answer 94 views
3 answers 177 views
1 answer 128 views
...