Lodash _.truncate() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
String

Definition

Shortens a string when it is longer than a maximum length, then appends an omission marker (default "..."). Optional separator cuts at a word or pattern boundary. Part of Lodash String (stable since 4.0.0 — not deprecated). Note: options.length includes the omission string.

Pass the string and options shown below. Check the return type before you chain another helper.

Syntax

Call _.truncate. Start with this line.

Lodash
_.truncate([string=''], [options={}])
CallWhat it does
_.truncate([string=''], [options={}])Primary signature.
_.truncate(string)Transform or inspect a string.

Prefer import truncate from "lodash/truncate" when you want a smaller bundle.

Library declarations
Lodash
_.truncate([string=''], [options={}])

Parameters

ParameterDescription
stringOptional. Value to truncate (default '')
options.lengthOptional. Max result length (default 30, includes omission)
options.omissionOptional. Suffix when truncated (default '...')
options.separatorOptional. String or RegExp cut point before the limit

Return Value

Return ValueDescription
*Truncated string (or original if short enough)

Lodash Examples

Example 1 — Official: Default Truncate

Default max length is 30, omission is "...".

Lodash
console.log(
  _.truncate("hi-diddly-ho there, neighborino")
);
// 'hi-diddly-ho there, neighbo...'
Try It Yourself

How It Works

  1. Long. The string is longer than 30 characters.
  2. Budget. Keep room for '...' inside the length.
  3. Cut. Content ends at neighbo.
  4. Docs. Matches the official first example.

Example 2 — Official: Space Separator

Cut at the last space before the length limit.

Lodash
console.log(
  _.truncate("hi-diddly-ho there, neighborino", {
    length: 24,
    separator: " "
  })
);
// 'hi-diddly-ho there,...'
Try It Yourself

How It Works

  1. length. Cap the result at 24 characters.
  2. separator. Prefer a space break over a mid-word cut.
  3. Result. Ends after there, then ....
  4. Docs. Matches the official second example.

Example 3 — Official: RegExp Separator

Use a pattern to drop trailing commas/spaces cleanly.

Lodash
console.log(
  _.truncate("hi-diddly-ho there, neighborino", {
    length: 24,
    separator: /,? +/
  })
);
// 'hi-diddly-ho there...'
Try It Yourself

How It Works

  1. RegExp. /,? +/ matches an optional comma plus spaces.
  2. Cut. Truncation lands on a cleaner word boundary.
  3. Result. No leftover comma before ....
  4. Docs. Matches the official third example.

Example 4 — Official: Custom Omission

Swap "..." for your own marker.

Lodash
console.log(
  _.truncate("hi-diddly-ho there, neighborino", {
    omission: " [...]"
  })
);
// 'hi-diddly-ho there, neig [...]'
Try It Yourself

How It Works

  1. omission. Uses ' [...]' instead of '...'.
  2. length. Still defaults to 30 — longer omission means less content.
  3. Result. Ends with a bracketed marker.
  4. Docs. Matches the official fourth example.

Example 5 — Short String Unchanged

No omission is added when the text already fits.

Lodash
console.log(_.truncate("short text", { length: 30 }));
// 'short text'
Try It Yourself

How It Works

  1. Compare. String length is under the max.
  2. Skip. No cut and no omission.
  3. Return. Original text as-is.
  4. Use. Safe for mixed short/long previews.

Browser & Runtime Support

_.truncate is a Lodash String helper available since 4.0.0. It runs anywhere Lodash runs — modern browsers (via CDN or bundle) and Node.js / Bun / Deno with npm install lodash.

✓ Stable · Lodash 4.x

_.truncate()

Available in [email protected] full builds and the lodash/truncate modular import. Works in evergreen browsers and current Node LTS when Lodash is installed.

100% With Lodash 4.x
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
_.truncate Since 4.0.0

Bottom line: Safe for production once Lodash is on the page. Prefer import truncate from "lodash/truncate" for smaller builds. There is no single native truncate-with-options helper — CSS line-clamp is a display alternative.

Frequently Asked Questions

_.truncate([string=''], [options={}]) shortens a string longer than options.length and appends an omission (default '...'). Official default: 'hi-diddly-ho there, neighbo...'.
Yes. The maximum length counts the full result, including the omission string. With default length 30 and '...', the kept text is shorter than 30.
separator (string or RegExp) cuts at a natural break before the length limit — for example a space or /,? +/ — so you do not split mid-word when possible.
If string.length is less than or equal to length, _.truncate returns the string unchanged (no omission added).
Yes. Set options.omission — official example uses ' [...]'.
Use import truncate from "lodash/truncate" or require("lodash/truncate"). Full build: import _ from "lodash" then _.truncate.

Next: _.unescape()

Convert HTML entities back into characters.

_.unescape() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

10 people found this page helpful