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

1 Answer

0 votes
const str = 'javascript c c++ java c++ javascript php php';

const totalUniqueWords = new Set(str.split(' ')).size;

console.log(totalUniqueWords);

 
 

 
/*
run:

5

*/

 



answered Feb 10, 2022 by avibootz

Related questions

2 answers 251 views
1 answer 209 views
1 answer 210 views
1 answer 217 views
1 answer 198 views
1 answer 203 views
1 answer 251 views
...