How to count only the unique words from a string in Node.js

1 Answer

0 votes
const str = 'node.js c c++ java c++ node.js php php';

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

console.log(totalUniqueWords);

 
 

 
/*
run:

5

*/

 



answered Feb 10, 2022 by avibootz
...