.padEnd()
Anonymous contributor
Published Jun 8, 2024
Contribute to Docs
In JavaScript, the .padEnd()
method is used with JavaScript strings to pad the end of a string with another string, until it reaches a specified length. It was introduced with ECMAScript 2017.
Syntax
string.padEnd(targetLength, padString)
string
: The original string to be padded.targetLength
: The desired length of the resulting string after padding.padString
: The string to pad the original string with, defaulting to a space if not provided.
Example
In the following example, a string variable called text
contains the sentence ‘hello world’. The .padEnd()
method is used to append more characters (in this example exclamation marks) to the end of the text, until it reaches the specified length of 15 characters.
let text = 'hello world';console.log(text.padEnd(15, '!'));
This results in the following output:
'hello world!!!!'
Codebyte Example
All contributors
- Anonymous contributor
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn JavaScript on Codecademy
- Career path
Front-End Engineer
Front-end engineers work closely with designers to make websites beautiful, functional, and fast.Includes 34 CoursesWith Professional CertificationBeginner Friendly115 hours - Free course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner Friendly15 hours