Lodash _.padStart() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
String

Definition

Pad a string on the left until it reaches a target length. Part of Lodash String (stable — not deprecated). Padding characters are truncated if they exceed the needed width.

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

Syntax

Call _.padStart. Start with this line.

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

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

Library declarations
Lodash
_.padStart([string=''], [length=0], [chars=' '])

Parameters

ParameterDescription
stringOptional. Source string (default '')
lengthOptional. Target length (default 0)
charsOptional. Pad characters (default ' ')

Return Value

Return ValueDescription
*New padded string

Lodash Examples

Example 1 — Official: Pad with Spaces

Default fill character is a space.

Lodash
_.padStart("abc", 6);
// → "   abc"
Try It Yourself

How It Works

  1. Length. "abc" is 3; target is 6.
  2. Need. 3 characters of padding on the left.
  3. Default. chars defaults to space.
  4. Docs. Matches the official first example.

Example 2 — Official: Custom Pad Characters

Multi-character pads repeat and truncate to fit.

Lodash
_.padStart("abc", 6, "_-");
// → "_-_abc"
Try It Yourself

How It Works

  1. Need. Still 3 pad characters.
  2. Cycle. "_-" repeats as "_-_"…
  3. Truncate. Only the first 3 chars are used.
  4. Docs. Matches the official second example.

Example 3 — Official: Already Long Enough

No padding when length is not greater than the string.

Lodash
_.padStart("abc", 3);
// → "abc"
Try It Yourself

How It Works

  1. Compare. String length equals target.
  2. Skip. No pad characters are added.
  3. Same. Returns "abc" unchanged.
  4. Docs. Matches the official third example.

Example 4 — Leading Zeros

Common for IDs, invoices, and fixed-width numbers.

Lodash
_.padStart("42", 5, "0");
// → "00042"

_.padStart(String(7), 3, "0");
// → "007"
Try It Yourself

How It Works

  1. Chars. Use "0" as the pad character.
  2. Width. Target length is the full field width.
  3. Numbers. Convert with String(n) first if needed.
  4. Use. Align codes in logs, files, and UI labels.

Example 5 — padStart vs padEnd

Same length and chars; opposite sides.

Lodash
console.log(_.padStart("abc", 6, "*")); // "***abc"
console.log(_.padEnd("abc", 6, "*"));   // "abc***"
Try It Yourself

How It Works

  1. padStart. Stars go on the left.
  2. padEnd. Stars go on the right.
  3. Both. Use _.pad to balance both sides.
  4. Pick. Match the side your layout needs.

Browser & Runtime Support

_.padStart is a Lodash String helper available in 4.x. It runs anywhere Lodash runs — modern browsers (via CDN or bundle) and Node.js / Bun / Deno with npm install lodash. Native String.prototype.padStart (ES2017) covers the same idea in current engines.

✓ Stable · Lodash 4.x

_.padStart()

Available in [email protected] full builds and the lodash/padStart 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
_.padStart Lodash 4.x

Bottom line: Safe for production once Lodash is on the page or in your bundle. Prefer import padStart from "lodash/padStart" for smaller builds. Use native padStart in modern-only codebases if you prefer zero Lodash for this helper.

Frequently Asked Questions

_.padStart([string=''], [length=0], [chars=' ']) pads string on the left until it reaches length. Official: _.padStart('abc', 6) → ' abc'.
If string.length >= length, the original string is returned unchanged. Official: _.padStart('abc', 3) → 'abc'.
Yes. Official: _.padStart('abc', 6, '_-') → '_-_abc'. Extra pad chars are truncated to fit the needed width.
Pass '0' as chars: _.padStart('42', 5, '0') → '00042'.
padStart adds on the left; padEnd adds on the right. _.pad() pads both sides.
Yes. String.prototype.padStart (ES2017) is similar. Lodash remains useful for older runtimes and Lodash pipelines.

Next: _.parseInt()

Parse a string into an integer with an optional radix.

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