String

String.prototype.padEnd

Pads the current string from the end with a given string until the resulting string reaches the given length

Syntax

JavaScript
string.padEnd(targetLength, padString?)

Parameters

ParameterTypeDescription
targetLengthnumberThe length of the resulting string after padding
padStringstringThe string to pad with. Defaults to space

Return Value

A new string of the specified length with padding applied from the end

Examples

Basic Usage
const str = 'abc';
console.log(str.padEnd(6, '.')); // 'abc...'
Practical Example
const items = ['Name', 'Age', 'City'];
const padded = items.map(i => i.padEnd(10));
console.log(padded.join('|'));
Advanced Usage
const price = '9.99';
console.log(price.padEnd(8, ' ')); // '9.99    '

Understanding String.prototype.padEnd

The String.prototype.padEnd method in JavaScript pads the current string from the end with a given string until the resulting string reaches the given length. It belongs to the String object and is one of the most widely used methods for working with string values in modern JavaScript and TypeScript applications.

The method signature is string.padEnd(targetLength, padString?). It accepts 2 parameters: targetLength, padString. When called, it returns a new string of the specified length with padding applied from the end. Understanding when and how to use padEnd() helps you write more expressive, readable code.

Common use cases for String.prototype.padEnd include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like string-padstart, string-repeat, enabling you to chain operations together for complex data manipulation pipelines.

Browser support for String.prototype.padEnd is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.

Browser Compatibility

Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.

Related Methods

More String Methods

Other methods in the String object

Related Tools

More String Methods

Explore JavaScript Methods

Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.