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 109 views
1 answer 129 views
1 answer 106 views
1 answer 112 views
112 views asked Oct 24, 2021 by avibootz
1 answer 100 views
3 answers 191 views
1 answer 138 views
...