How to count words in a string ignore spaces with TypeScript

1 Answer

0 votes
const str = "typescript    php  c   c++";
 
const len = str.split(" ").filter(word => word !== '').length;

console.log(len); 
  
  
   
     
     
/*
run:
     
4
     
*/

 



answered Feb 15, 2022 by avibootz
...