mridul037 Posted on Nov 20, 2019 count number of word in string using javascript. #javascript function countWords(str) { let c=0; for (x in str){ if(str[x]==" ") c++; } return c+1; } Top comments (1) Subscribe Submit Preview Dismiss Collapse Expand DeLiXx DeLiXx DeLiXx Follow Joined Sep 2, 2019 • Nov 25 '19 Dropdown menu Copy link Hide or you do str.split(" ").length which is not only easier to read but also faster Code of Conduct • Report abuse
Top comments (1)
or you do
which is not only easier to read but also faster