showing results for - "javascript count words in string"
Remington
13 Jun 2020
1var str = "your long string with many words.";
2var wordCount = str.match(/(\w+)/g).length;
3alert(wordCount); //6
4
5//    \w+    between one and unlimited word characters
6//    /g     greedy - don't stop after the first match
María Paula
02 Feb 2017
1<html>
2<body>
3   <script>
4      function countWords(str) {
5         str = str.replace(/(^\s*)|(\s*$)/gi,"");
6         str = str.replace(/[ ]{2,}/gi," ");
7         str = str.replace(/\n /,"\n");
8         return str.split(' ').length;
9      }
10      document.write(countWords("   Tutorix is one of the best E-learning   platforms"));
11   </script>
12</body>
13</html>
queries leading to this page
count the number of words in a string javascriptcount number of words a sentence javascriptjs string word countjavascript count string wordsjavascript word counthow to count words javascripthow t0 count the number of words in a string in javascripthow to count the number of words in a string javascriptstring word count javascriptcount words of string javascripthow to count the words in a string in javascriptcan i count words in a string variable in javascripthow to calculate word count in string js count words in string javascripthow to count number of words using javascriptcount number of words javascripthow to count words in javascriptjavascript program to count number of words in stringfind number words in string in jscount words javascriptfind words and count in jshow many words in a sentence javascriptjs get amount of words in stringcount the number of words in an string 2c javascriptcount number of words in javascriptjavascript string count wordshow to count words in jshow to get words counts from string in java javascriptjs count number of words in a stringcount words in text javascript javascript number of words in stringjs count wordsjs count words in stringcount words in a string jsword count jscount word and space in text javascriptjs count wordcount of words in jscount number of words jscount number of words in string javascriptcount word in string jscount words in a sentence javascriptjavascript count words in stringjavascript how to count number of words in a stringjs count words in a sentencejs count word in stringcount word to jsjavascript count wordshow many words in a string javascript solutionjavascript count number of words in a stringcount words in a string javascriptword count in string javascripthow to count words in string in javascriptcounting words in a sentence javascriptcount words in javascript stringwords count in jsjavascript function that counts the number of words in a stringcount words in string jscount words in sentence javascriptcount total words jscheck number of words in string javascriptcount number of words in a string in javascriptcount characters in word javascriptcount words with javascripthow many words javascripthow to count number of words in js stringcount word js3 write a javascript program to count number of words in string how to count words in a text in javascripthow to count the words in javascripthow to find number of words in a string in javascripthow to count word in javascriptcount words jshow to count the number of words in a string in javascriptcount words in javascriptjavascript count words in string