Answers for "count number of word in javascript"

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
0

js count word

return str.split(' ').length;
Posted by: Guest on August-08-2021

Code answers related to "count number of word in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language