Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

count word and space in text javascript

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

PREVIOUS NEXT
Code Example
Javascript :: javascript Using Math.min() on an Array 
Javascript :: serving html file using node.js 
Javascript :: node.js - How do I convert an image to a base64-encoded data URL 
Javascript :: dangerouslySetInnerHTML 
Javascript :: string reverse javascript 
Javascript :: how to pause js execution 
Javascript :: javascript object to query params 
Javascript :: expo build ios 
Javascript :: js get hostname from url 
Javascript :: express request body undefined 
Javascript :: js get first letter of string 
Javascript :: react js image path src from local folder 
Javascript :: javascript array push element at index 
Javascript :: click right mouse javascript 
Javascript :: jquery checkvalidity 
Javascript :: javascript constructor and prototype 
Javascript :: vuejs props declare prop with multiple types 
Javascript :: set label text in jquery 
Javascript :: chartjs lineTension 
Javascript :: js sort by date 
Javascript :: convert days into year month 
Javascript :: filter javascript 
Javascript :: react keydown event listener 
Javascript :: how to filter nested array of objects in javascript 
Javascript :: javascript check image src 
Javascript :: .includes( string 
Javascript :: ionic capacitor keyboard push content up 
Javascript :: complex json example 
Javascript :: url params vue 
Javascript :: typeorm subquery 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =