Removes trailing whitespace — or a custom set of characters — from the end of a string. Leading characters stay. Part of Lodash String (stable since 4.0.0 — not deprecated; _.trimRight is an alias).
Pass the string and options shown below. Check the return type before you chain another helper.
Syntax
Call _.trimEnd. Start with this line.
Lodash
_.trimEnd([string=''], [chars=whitespace])
Call
What it does
_.trimEnd([string=''], [chars=whitespace])
Primary signature.
_.trimEnd(string)
Transform or inspect a string.
Prefer import trimEnd from "lodash/trimEnd" when you want a smaller bundle.
Library declarations
Lodash
_.trimEnd([string=''], [chars=whitespace])
Parameters
Parameter
Description
string
Optional. Value to trim (default '')
chars
Optional. Characters to strip from the end (default: whitespace)
Return Value
Return Value
Description
*
New string with trailing chars removed
Lodash Examples
Example 1 — Official: Trim Trailing Whitespace
Spaces on the right go away; spaces on the left stay.
_.trimEnd is a Lodash String helper available since 4.0.0 (_.trimRight alias). It runs anywhere Lodash runs — modern browsers (via CDN or bundle) and Node.js / Bun / Deno with npm install lodash.
✓ Stable · Lodash 4.x
_.trimEnd()
Available in [email protected] full builds and the lodash/trimEnd modular import. Works in evergreen browsers and current Node LTS when Lodash is installed.
100%With Lodash 4.x
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.jsSupported · Server runtime
Supported
Android WebViewSupported · Modern WebView
Full support
_.trimEndSince 4.0.0
Bottom line: Safe for production once Lodash is on the page. Prefer import trimEnd from "lodash/trimEnd" for smaller builds. Native String#trimEnd is fine for whitespace-only cases without Lodash.
Frequently Asked Questions
_.trimEnd([string=''], [chars=whitespace]) removes trailing whitespace or specified characters from the end only. Official: _.trimEnd(' abc ') → ' abc'.
No. Leading characters — including leading whitespace — are preserved.
It is a set of characters to strip from the end — not an exact substring. _.trimEnd('-_-abc-_-', '_-') removes any mix of '_' and '-' from the right.
_.trim cleans both ends. _.trimStart cleans only the start. _.trimEnd cleans only the end.
Yes. _.trimRight is an alias of _.trimEnd in Lodash 4.x. Prefer _.trimEnd in new code.
Use import trimEnd from "lodash/trimEnd" or require("lodash/trimEnd"). Full build: import _ from "lodash" then _.trimEnd.