Lodash _.words() Method
The _.words() method is used to split the given string into an array of words. A pattern can be specified so that certain words can be removed from the string.
_.words( string, pattern )
Parameters: This method accepts two parameters as mentioned above and described below:
- string: It is the string that is to be split. The default value is an empty string.
- pattern: It is a pattern on the basis of which the words would be matched. It is an optional parameter.
Return Value: This method returns an array of words according to the pattern.
[ 'Geeks', 'for', 'Geeks' ]
[ 'for', index: 6, input: 'Geeks for Geeks', groups: undefined ]
[ '&', 'Geeks', 'for', 'Geeks', '&' ]