How to count the unique elements of an array in TypeScript

1 Answer

0 votes
const arr = ['c', 'typescript', 'c++', 'typescript', 'typescript', 'php'];

const unique_elements = new Set(arr).size;

console.log(unique_elements);
  
  
  
  
  
/*
run:
  
4
  
*/

  
  
 

 



answered Jun 27, 2022 by avibootz
...