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 140 views
1 answer 126 views
1 answer 127 views
1 answer 129 views
1 answer 121 views
1 answer 126 views
1 answer 164 views
...