How to count only the unique words from a string in TypeScript

1 Answer

0 votes
const str: string = 'typescript c c++ java c++ typescript php php';
 
const totalUniqueWords: number = new Set(str.split(' ')).size;
 
console.log(totalUniqueWords);
  
 
  
/*
run:
 
5
 
*/
 

 



answered Feb 10, 2022 by avibootz
edited Sep 20, 2024 by avibootz

Related questions

2 answers 159 views
1 answer 127 views
1 answer 127 views
1 answer 130 views
1 answer 121 views
1 answer 126 views
1 answer 165 views
...