Lodash _.trimStart() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
String

Definition

Removes leading whitespace — or a custom set of characters — from the start of a string. Trailing characters stay. Part of Lodash String (stable since 4.0.0 — not deprecated; _.trimLeft is an alias).

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

Syntax

Call _.trimStart. Start with this line.

Lodash
_.trimStart([string=''], [chars=whitespace])
CallWhat it does
_.trimStart([string=''], [chars=whitespace])Primary signature.
_.trimStart(string)Transform or inspect a string.

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

Library declarations
Lodash
_.trimStart([string=''], [chars=whitespace])

Parameters

ParameterDescription
stringOptional. Value to trim (default '')
charsOptional. Characters to strip from the start (default: whitespace)

Return Value

Return ValueDescription
*New string with leading chars removed

Lodash Examples

Example 1 — Official: Trim Leading Whitespace

Spaces on the left go away; spaces on the right stay.

Lodash
console.log(JSON.stringify(_.trimStart("  abc  ")));
// 'abc  '
Try It Yourself

How It Works

  1. Input. Spaces sit on both sides of abc.
  2. Start. Leading spaces are removed.
  3. End. Trailing spaces remain.
  4. Docs. Matches the official first example.

Example 2 — Official: Custom Characters

Strip a character set from the start only.

Lodash
console.log(_.trimStart("-_-abc-_-", "_-"));
// 'abc-_-'
Try It Yourself

How It Works

  1. Set. '_-' means strip _ or -.
  2. Left. Leading -, _, - are removed.
  3. Right. The trailing -_- stays.
  4. Docs. Matches the official second example.

Example 3 — Trailing Padding Is Kept

Useful when right-side spacing should remain.

Lodash
var cell = "  value    ";

console.log(JSON.stringify(_.trimStart(cell)));
// 'value    '
Try It Yourself

How It Works

  1. Left. Leading spaces are stripped.
  2. Right. Trailing padding stays for alignment.
  3. Result. Content starts at column zero; end spaces remain.
  4. Use. Cleaning prefixes without changing right padding.

Example 4 — Clean Leading Spaces in a List

Map _.trimStart over several values.

Lodash
console.log(
  _.map(["  foo", "  bar  "], _.trimStart)
);
// ['foo', 'bar  ']
Try It Yourself

How It Works

  1. map. Runs _.trimStart on each item.
  2. First. ' foo' → 'foo'.
  3. Second. Trailing spaces on bar stay.
  4. Tip. Use _.trim if both ends should go.

Example 5 — vs _.trim / _.trimEnd

Pick the helper that matches the side you want cleaned.

Lodash
var s = "  abc  ";

console.log(JSON.stringify(_.trimStart(s))); // 'abc  '
console.log(JSON.stringify(_.trimEnd(s)));   // '  abc'
console.log(JSON.stringify(_.trim(s)));      // 'abc'
Try It Yourself

How It Works

  1. trimStart. Cleans the left side only.
  2. trimEnd. Cleans the right side only.
  3. trim. Cleans both sides.
  4. Next. See _.truncate.

Browser & Runtime Support

_.trimStart is a Lodash String helper available since 4.0.0 (_.trimLeft 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

_.trimStart()

Available in [email protected] full builds and the lodash/trimStart 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
_.trimStart Since 4.0.0

Bottom line: Safe for production once Lodash is on the page. Prefer import trimStart from "lodash/trimStart" for smaller builds. Native String#trimStart is fine for whitespace-only cases without Lodash.

Frequently Asked Questions

_.trimStart([string=''], [chars=whitespace]) removes leading whitespace or specified characters from the start only. Official: _.trimStart(' abc ') → 'abc '.
No. Trailing characters — including trailing whitespace — are preserved.
It is a set of characters to strip from the start — not an exact substring. _.trimStart('-_-abc-_-', '_-') removes any mix of '_' and '-' from the left.
_.trim cleans both ends. _.trimEnd cleans only the end. _.trimStart cleans only the start.
Yes. _.trimLeft is an alias of _.trimStart in Lodash 4.x. Prefer _.trimStart in new code.
Use import trimStart from "lodash/trimStart" or require("lodash/trimStart"). Full build: import _ from "lodash" then _.trimStart.

Next: _.truncate()

Shorten a string and append an omission marker.

_.truncate() 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