Answers for "how to do a word count in javascript"

1

word count js

function calculateWordCount(text) {
        const wordsArr = text.trim().split(" ")
        return wordsArr.filter(word => word !== "").length
    }
Posted by: Guest on November-01-2021
1

count number of word in javascript

<html>
<body>
   <script>
      function countWords(str) {
         str = str.replace(/(^s*)|(s*$)/gi,"");
         str = str.replace(/[ ]{2,}/gi," ");
         str = str.replace(/n /,"n");
         return str.split(' ').length;
      }
      document.write(countWords("   Tutorix is one of the best E-learning   platforms"));
   </script>
</body>
</html>
Posted by: Guest on July-28-2020

Code answers related to "how to do a word count in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language