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 132 views
1 answer 115 views
1 answer 115 views
1 answer 119 views
1 answer 113 views
1 answer 115 views
1 answer 153 views
...