By the end of this tutorial, you’ll use Lodash’s _.truncate() confidently in real JavaScript projects.
01
Core Syntax
Call _.truncate(str, options) with length and omission.
02
Length limit
Set length to the max visible characters.
03
Omission suffix
Customize omission (default ...).
04
Word boundaries
Use separator to avoid mid-word cuts.
05
UI previews
Build card excerpts and table cell snippets.
06
Non-mutating
Original string stays intact.
Fundamentals
What Is _.truncate()?
_.truncate() shortens a string to a maximum length and appends an omission (default ...) when the text exceeds that limit. Optional separator lets you cut at word boundaries instead of mid-word—ideal for card excerpts, notification previews, and table cells.
💡
Beginner tip
Think of _.truncate(text, { length: 80, separator: ' ' }) as “give me a readable preview that fits in this UI slot.” The original string is never modified.
Previous: _.trimStart() for leading whitespace removal.
Wrap Up
Conclusion
Use _.truncate() whenever UI space is limited and readability matters. Configure length, omission, and separator once per component and reuse across card lists, notifications, and data tables.
Set length to fit your UI component, including omission width
Use separator: ' ' for readable word-boundary cuts
Reuse one truncate helper across card and list components
Test with your longest real content samples
Import lodash/truncate for bundle size
❌ Don’t
Truncate security-sensitive text without reviewing full content links
Assume length counts bytes instead of characters
Cut mid-word in headings when separator can help
Use truncate for validation—use max-length on input instead
Forget that omission counts toward length
Summary
Key Takeaways
📄01
Non-mutating
New string returned
Basics
📄02
Length + omission
Fit UI slots
Core
📄03
Separator
Word-aware cuts
Pattern
📄04
UI previews
Cards & tables
Use case
📄05
trimStart
Prior method
Nav
❓ Frequently Asked Questions
_.truncate() shortens a string to a maximum length and appends an omission string (default '...') when the text is longer than the limit.
No. JavaScript strings are immutable. _.truncate() always returns a new string.
An options object with length (max characters), omission (suffix when truncated, default '...'), and separator (truncate at last occurrence of separator before the limit, default a space).
slice() cuts at an exact index and does not add an omission or respect word boundaries. _.truncate() is built for readable UI excerpts with ellipsis.
When set, truncation happens at the last separator before the length limit so you do not cut mid-word. Use separator: ' ' for word-aware previews or a regex for finer control.
Use it for card excerpts, table cells, notification previews, and any UI that must show a short, readable snippet of longer text.
Did you know?
_.truncate counts the omission toward length—so a 30-character limit with ... leaves 27 characters of visible text. Use separator to avoid awkward mid-word cuts in headings.