“Word Count Javascript” Kode Jawaban

Word Count Javascript

const str = "hello world";
console.log(str.split(' ').length); // @output 2
Aryamitra Chaudhuri

Metode String JavaScript Jumlah kata di dalam string

<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>
Yawning Yak

Hitung kata dan ruang dalam javascript teks

<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>
Difficult Deer

Cara memeriksa berapa banyak string dalam kalimat JavaScript

function WordCounter (str) {
	var words = str.split(" ").length;
	return words;
}
// this should work!
TechWhizKid

JS Count Word

return str.split(' ').length;
Borma

Jawaban yang mirip dengan “Word Count Javascript”

Pertanyaan yang mirip dengan “Word Count Javascript”

Lebih banyak jawaban terkait untuk “Word Count Javascript” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya