Answers for "how to count words in a string javascript"

2

javascript count words in string

var str = "your long string with many words.";
var wordCount = str.match(/(w+)/g).length;
alert(wordCount); //6

//    w+    between one and unlimited word characters
//    /g     greedy - don't stop after the first match
Posted by: Guest on January-31-2021
0

how to check how many strings are in a sentence javascript

function WordCounter (str) {
	var words = str.split(" ").length;
	return words;
}
// this should work!
Posted by: Guest on June-02-2020

Code answers related to "how to count words in a string javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language