How to count words in a string ignore spaces with Node.js

1 Answer

0 votes
const str = "node.js    php  c    c++";
  
const len = str.split(" ").filter(word => word !== '').length;
  
console.log(len); 
  
  
    
      
      
/*
run:
      
4
      
*/

 



answered Feb 15, 2022 by avibootz
...