Home > word count in javascript

Show specific number of words in string using JavaScript

<p id="shortWord"></p> <script> var word = "Lorem Ipsum is simply dummy text of the printing and typesetting industry." var wordArr = word.split(" "); var wordShort = wordArr.splice(0, 5).join(" "); document.getElementById('shortWord').innerHTML= wordShort; </script> Output: "Lorem Ipsum is simply dummy"  

This Article is TAGGED in , . Read more