-
Couldn't load subscription status.
- Fork 0
ProtoString wordCount() Method
<< Back to Miscellaneous Methods
Leaving the parameter undefined or filling it in as "number" will return the total number of words.
'I love coffee. ♥'.wordCount(); // returns 3
'I love coffee. ♥'.wordCount('number'); // returns 3Filling in the parameter as "array" will return an array with all words that occur in the string. As an array, the total number of words can be accessed via the length property
'I love coffee. ♥'.wordCount('array'); // returns ['I', 'love', 'coffee']Filling in the parameter as "object" will return the words as an object. The total number of words can then be accessed via the words property
'I love coffee. ♥'.wordCount('object'); // returns {0:'I', 1:'love', 2:'coffee', words:3}The wordCount method returns the total number of words in a string. The return value can be the number of words, or an array or object which contains each word.
String.wordCount(type);| Parameter | Description |
|---|---|
| Type | A string representing the data type to be returned. Possible values are number, array, and object. Defaults to number if left undefined. |
Home • History • ProtoString • Created by Seth Clydesdale