Skip to main content Accessibility Feedback

Strings

String.prototype.padEnd()

Add characters to the end of a string if it’s less than a certain length. Accepts two arguments: the length the string should be, and what characters to add if it’s not that length. The characters to use is optional, and defaults to a space ().

// Add a leading zero for hours below 10
let minutes0 = '0';
let minutes12 = '12';

// returns "00"
minutes0.padEnd(2, '0');

// returns "12"
minutes12.padEnd(2, '0');

Preorder my new course on Web Components! Want to learn how to build Web Components from scratch, master best practices, and more? Preorder today and get $100 off of the launch price.


Find this useful? You can support my work by purchasing an annual membership.