my_text is your source string add any character you want to be used as a separator my_text.split(/[\s\.,;]+/).length; Note that depending on your source string, your array could contain empty elements. See http://stackoverflow.com/questions/281264/remove-empty-elements-from-an-array-in-javascript to remove empty elements in an array.
Javascript
PhantomJS: wait for it
When you want to take screenshots with PhantomJS, you probably need to wait before your page is completely loaded. I mean all resources are loaded and scripts executed. Use the following code to delay your screenshot : var page = new WebPage(); page.open(‘http://stackoverflow.com/’, function (status) { just_wait(); }); function just_wait() { setTimeout(function() { page.render(‘screenshot.png’); phantom.exit(); …