Lodash _.padEnd() Method

Beginner
⏱️ 7 min read
📚 Updated: Jul 2026
🎯 6 Examples + 3 Try It
String utilities

What You’ll Learn

By the end of this tutorial, you’ll use Lodash’s _.padEnd() confidently in real string workflows.

01

Core Syntax

Call _.padEnd(string, length, [chars]).

02

Right Padding

Characters append to the end until target length.

03

Custom Fill

Use dashes, dots, or any fill character.

04

Tabular Output

Align names and values in fixed-width columns.

05

padStart vs padEnd

Know left vs right padding for your layout.

06

Production Tips

Prefer native padEnd() when lodash is not imported.

What Is _.padEnd()?

_.padEnd() appends padding characters to the end of a string until it reaches the target length. Default padding is a space. Pair with _.padStart() for left padding or _.pad() for both sides.

💡
Beginner tip

Think of _.padEnd(name, 10) as “make this label ten characters wide by adding spaces on the right.” Great for console tables and fixed-width columns.

📝 Syntax

javascript
_.padEnd(string, length, [chars=' '])

Syntax Rules

  • string — The source string to pad (coerced if not a string).
  • length — Target total length after padding.
  • chars — Optional fill string (default space). Only the first character is used for multi-char strings in lodash.
  • Return value — New padded string; original unchanged.
  • Shorter strings — If the string is already >= length, it is returned unchanged.
javascript
import padEnd from "lodash/padEnd";

const label = "Hello";
const aligned = padEnd(label, 10);
// -> "Hello     "

⚡ Quick Reference

TaskCode patternResult
Default spaces_.padEnd(str, 10)Right-pad with spaces
Custom fill_.padEnd(str, 10, '-')Dash padding
Align column_.padEnd(name, 12)Fixed-width labels
No change_.padEnd('Hello', 3)Already long enough
Left pad_.padStart(str, n)Opposite side
Native altstr.padEnd(10)ES2017 built-in
Mutates?
No

Returns new string

Side
End

Right padding

Default fill
Space

Single space char

Native
padEnd()

Built-in equivalent

🧰 Parameters

string Required

Input string to extend on the right.

_.padEnd(label, 8)
length Required

Desired total character count.

_.padEnd(s, 10)
chars Optional

Padding character(s); defaults to space.

_.padEnd(s, 8, '.')
return value New string

Padded copy; original unchanged.

const row = _.padEnd(cell, 6)

Examples Gallery

Practical _.padEnd() patterns with copy-ready code and interactive Try It Yourself labs.

📚 Getting Started

Right-pad a greeting with spaces to a fixed width.

Example 1 — Basic right-padding with spaces

Pad Hello to ten characters with trailing spaces.

javascript
const original = "Hello";
const padded = _.padEnd(original, 10);

console.log(JSON.stringify(padded));
// -> "Hello     "

console.log(original);
// still "Hello"
Try It Yourself

How It Works

_.padEnd() appends spaces until the total length is 10.

📈 Practical Patterns

Custom fill characters and real formatting tasks.

Example 2 — Custom dash padding

Use hyphens instead of spaces for visual separators.

javascript
const padded = _.padEnd("Hello", 10, "-");

console.log(padded);
// -> "Hello-----"
Try It Yourself

How It Works

The third argument replaces the default space fill character.

Example 3 — Align tabular data

Pad names and ages for readable console output.

javascript
const rows = [
  { name: "John", age: 30 },
  { name: "Alice", age: 25 },
  { name: "Bob", age: 35 }
];

rows.forEach(({ name, age }) => {
  const line = _.padEnd(name, 10) + " | " + _.padEnd(String(age), 5);
  console.log(line);
});
Try It Yourself

How It Works

Fixed-width columns make scanned output easier to read.

Example 4 — String already long enough

No padding when target length is shorter than the string.

javascript
const result = _.padEnd("Hello", 3);
console.log(result);
// -> "Hello"

How It Works

Lodash never truncates—only extends when needed.

Example 5 — Dynamic padding length

Compute width from runtime values.

javascript
const width = 10;
const fill = "*";
const padded = _.padEnd("Hello", width, fill);
// -> "Hello*****"

How It Works

Pass variables for length and fill when building dynamic layouts.

🚀 Beyond the Basics

Native alternatives and related padding helpers.

Example 6 — Native padEnd() alternative

ES2017 provides String.prototype.padEnd().

javascript
const str = "Hello";
const native = str.padEnd(10);
const lodash = _.padEnd(str, 10);
// both -> "Hello     "

How It Works

Use native padEnd() when lodash is not already in the bundle.

📋 Related string operations

Topic_.padEnd_.padStart_.padpadEnd()
Side paddedEnd (right)Start (left)BothEnd (right)
Custom charsYesYesYesYes
MutatesNoNoNoNo
Best forRight-align columnsZero-fill IDsCentered textModern native code

🧠 How _.padEnd() Works

1

Receive string

Lodash coerces the input to a string.

Input
2

Check length

If already at or past target length, return as-is.

Compare
3

Append fill

Repeat fill chars on the right until length is met.

Pad
=

Return result

New string returned; original unchanged.

Done

📝 Notes

  • _.padEnd() pads on the right only.
  • If length is less than or equal to the string length, the string is returned unchanged.
  • Default fill is a single space character.
  • Use _.padStart() for leading zeros or left alignment.
  • Strings are immutable—assign the return value.
  • Native String.padEnd() is equivalent in modern engines.

Conclusion

_.padEnd() is the Lodash helper for right-padding strings to a fixed width. Use it to align columns, format console output, and keep labels visually consistent.

💡 Best Practices

✅ Do

  • Assign the return value—strings are immutable
  • Specify radix explicitly when parsing user input
  • Use RegExp /g flag for global replacements
  • Validate counts and inputs before transforming
  • Prefer native methods when lodash is not already imported

❌ Don’t

  • Expect the original string variable to change in place
  • Forget radix when using _.parseInt on user data
  • Use string patterns when you need all matches replaced
  • Import all of Lodash for a single string call
  • Skip NaN checks after parsing

Key Takeaways

01

Right pad

Append fill on the end.

Basics
02

Length

Target total width.

Syntax
03

Custom fill

Optional chars arg.

Advanced
04

Tables

Align column data.

Pattern
05

padStart

Left padding sibling.

Related

❓ Frequently Asked Questions

It returns a new string padded on the right to the specified length with fill characters (default space).
No. Strings are immutable; a new padded string is returned.
The original string is returned unchanged—no truncation occurs.
padEnd adds padding on the right; padStart adds on the left (e.g. leading zeros).
Yes. String.prototype.padEnd() in ES2017 behaves similarly for most cases.
A single space character.
Did you know?

_.padEnd() only adds characters on the right. For IDs and invoice numbers that need leading zeros, use _.padStart(). For both sides see _.pad().

Practice _.padEnd() in the Live Editor

Open Try It, run the examples, and experiment with your own strings.

Open Try It editor →

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.

6 people found this page helpful