How to count words in javascript

  • 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.