Answers for "word count in string js"

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
1

word count js

function calculateWordCount(text) {
        const wordsArr = text.trim().split(" ")
        return wordsArr.filter(word => word !== "").length
    }
Posted by: Guest on November-01-2021
0

Counting no of word in javascript string

return str.split(' ').length;
Posted by: Guest on June-05-2020

Code answers related to "word count in string js"

Code answers related to "Javascript"

Browse Popular Code Answers by Language