How to count the unique elements of an array in Node.js

1 Answer

0 votes
const arr = ['c', 'node.js', 'c++', 'node.js', 'node.js', 'python', 'c#'];
 
const unique_elements = new Set(arr).size;

console.log(unique_elements);
  
  
  
  
/*
run:
  
5
  
*/

 



answered Jun 27, 2022 by avibootz
...