By the end of this tutorial, you’ll use Lodash’s _.words() confidently in real JavaScript projects.
01
Core Syntax
Call _.words(string) or pass a pattern.
02
Word array
Get tokens for analysis or UI tags.
03
Custom pattern
Pass RegExp for fine control.
04
vs split
Handles lodash word boundaries.
05
Word counts
Pair with _.size() or length.
06
Unicode
Works with many multilingual strings.
Fundamentals
What Is _.words()?
_.words() splits a string into an array of words using lodash default word boundaries or an optional custom RegExp. Use it for word counts, keyword extraction, tag generation, and text analysis pipelines.
💡
Beginner tip
Think of _.words(article) as “tokenize this text for counting, tagging, or search” with smarter boundaries than split(' ').
Foundation
📝 Syntax
javascript
_.words([string=''], [pattern])
javascript
import words from "lodash/words";
const tokens = words("Hello, Lodash words!");
// -> ["Hello", "Lodash", "words"]
Cheat Sheet
⚡ Quick Reference
Task
Code pattern
Result
Default
_.words('foo bar')
['foo','bar']
Custom regex
_.words(s, /[a-z]+/gi)
Pattern control
Word count
_.words(s).length
Token count
Punctuation
_.words('Hi!')
Cleaner than split
Unicode
_.words('你好,世界')
CJK support
Import
import words from 'lodash/words'
Per-method
Mutates?
No
Returns array
Pattern
Optional
Custom RegExp
vs split
Cleaner
Word rules
Use
Tokenize
Count & tags
Reference
🧰 Parameters
stringOptional
Source text to tokenize (default '').
patternOptional
RegExp or string pattern for word matching.
return valueArray
Array of extracted word strings.
default rulesLodash
Handles many Unicode letters and apostrophes in words.
Hands-On
Examples Gallery
Practical _.words() patterns with copy-ready code and interactive Try It Yourself labs.
📚 Getting Started
Core patterns for _.words() with copy-ready code.
Example 1 — Extract words from plain text
Split Lorem ipsum into an array of word tokens.
javascript
const text = "Lorem ipsum dolor sit amet";
console.log(_.words(text));
// -> ["Lorem", "ipsum", "dolor", "sit", "amet"]
_.words() closes out the Lodash string tutorial series with flexible tokenization. Extract words for counts, tags, and analysis—or pass a custom pattern when defaults are not enough. Head back to the String methods hub to review the full catalog.
_.words() splits a string into an array of words using lodash default word rules or an optional custom pattern.
split(' ') breaks only on spaces and leaves punctuation attached. _.words() handles lodash word boundaries and supports custom RegExp patterns.
Yes. Pass a RegExp as the second argument to control what counts as a word—for example /[a-zA-Z]+/g to strip punctuation.
Lodash word rules handle many Unicode letter sequences. Test with your target locales for edge cases.
Word counts, keyword extraction, building tag lists, and tokenizing text before analysis or search indexing.
No. It returns a new array; the source string is unchanged.
Did you know?
_.words is the last dedicated string-method tutorial in this series—the String methods hub links the full catalog. Default rules handle many Unicode scripts; pass a custom RegExp when you need stricter control.