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 262 views
1 answer 209 views
1 answer 210 views
1 answer 218 views
1 answer 198 views
1 answer 204 views
1 answer 253 views
...