JavaScript String padEnd() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Method

Definition

String.prototype.padEnd(targetLength, padString?) returns a new string padded at the end until it reaches targetLength. Default filler is a space. It never mutates the original.

Pass the required arguments shown below. Check return values and browser support before you rely on the result.

Syntax

Call string.padEnd. Start with this line.

JavaScript
str.padEnd(targetLength, padString?)
CallWhat it does
str.padEnd(targetLength, padString?)Primary signature.
string.padEnd(...)Call with the arguments your case needs.

Built into JavaScript. Call padEnd(...) on a string (or String instance) — no import required.

Library declarations
JavaScript
str.padEnd(targetLength, padString?)

Parameters

ParameterDescription
targetLengthRequired. Desired final .length (UTF-16 units)
padStringOptional. Filler; default " "; truncated if too long

Return Value

Return ValueDescription
*The value returned by string.padEnd().

JavaScript Examples

Example 1 — Basic Right Padding

Pad with dots or the default space until a target length.

JavaScript
console.log("hi".padEnd(5, "."));  // "hi..."
console.log("200".padEnd(5));      // "200  "
Try It Yourself

How It Works

  1. Measure the gap. "hi" has length 2; target is 5 → need 3 chars.
  2. Append the filler. Three "." characters make "hi...".
  3. Default is space. Omitting padString pads "200" with two spaces to length 5.
  4. New string only. The originals stay unchanged.

Example 2 — Repeat and Truncate the Filler

A short filler repeats; a long filler is cut to fit exactly.

JavaScript
console.log("abc".padEnd(10, "foo"));   // "abcfoofoof"
console.log("abc".padEnd(6, "123456")); // "abc123"
console.log("abc".padEnd(2, "."));      // "abc"
Try It Yourself

How It Works

  1. Repeat to fill. "foo" is tiled until seven chars are needed → "foofoof".
  2. Truncate excess. Only the first three digits of "123456" are used → "abc123".
  3. No-op when short. Target 2 is already less than length 3 → "abc".
  4. Exact length. Successful pads always end with result.length === targetLength.

Example 3 — padEnd() vs padStart()

Right pad for labels; left pad for leading zeros.

JavaScript
console.log("Name".padEnd(8, " ") + "Ada");   // "Name    Ada"
console.log("5".padStart(3, "0"));            // "005"
console.log("5".padEnd(3, "0"));              // "500"
Try It Yourself

How It Works

  1. padEnd for columns. "Name" grows to width 8 so values line up on the right.
  2. padStart for numbers. Leading zeros go on the left → "005".
  3. Same digit, opposite side. padEnd with "0" yields "500" — not zero-padding.
  4. Rule of thumb. Labels → padEnd; leading zeros → padStart.

Browser & Runtime Support

String.prototype.padEnd() is part of ES2017 and is Baseline Widely available across modern browsers.

✓ Baseline · ES2017

String.prototype.padEnd()

Supported in Chrome 57+, Firefox 48+, Safari 10+, Edge 15+, and Node.js 8+. Not available in Internet Explorer without a polyfill.

98% Modern browser support
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
String.padEnd() Excellent

Bottom line: Safe for modern web apps and current Node LTS releases. Feature-detect with if ("padEnd" in String.prototype) or use a small polyfill for very old targets.

Frequently Asked Questions

padEnd(targetLength, padString?) returns a new string padded at the end so its length reaches targetLength. The default padString is a single space.
If targetLength is less than or equal to str.length, padEnd() returns the original string unchanged (same contents).
padString is truncated so the result length equals targetLength. For example "abc".padEnd(6, "123456") returns "abc123".
padEnd adds padding after the text (on the right). padStart adds padding before the text (on the left). Both use the same length and padString rules.
No. Strings are immutable. padEnd() returns a new padded string.
padEnd uses UTF-16 code-unit length (same as str.length). Some emoji use two code units, so visual width and .length can differ.

Next: padStart()

Learn how to pad a string on the left — perfect for leading zeros.

padStart() 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.

11 people found this page helpful