liveBook · Manning

String.prototype.padEnd

As explained in Get Programming with JavaScript Next: New features of ECMAScript 2015, 2016, and beyond

A JavaScript string method that pads the end of a string with a specified filler until the string reaches a target length.

Need to make strings the same width? String.prototype.padEnd() adds a filler to the right until the result reaches the requested length. It takes a target length and an optional filler, which defaults to a space. If the original string is already that long or longer, it is returned unchanged. section 6.2

Choose a filler

'abc'.padEnd(6) returns 'abc '. With 'x', it returns 'abcxxx'; with 'xyz', it returns 'abcxyz'. If the filler would overshoot the target length, it is cut off: 'abc'.padEnd(5, '123') returns 'abc12'. section 6.2

How Get Programming with JavaScript Next: New features of ECMAScript 2015, 2016, and beyond covers it

How deep it goes
Defines its arguments and demonstrates default fillers, truncation, and unchanged strings when the target is shorter.
Examples
Uses abc with spaces, x, and xyz fillers, including a filler truncated to fit.
What you can do after
Apply it via String.prototype.padEnd to extend strings with repeated filler toward a target length.
How it connects
Connects string padding with padStart and repeat.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Get Programming with JavaScript Next: New features of ECMAScript 2015, 2016, and beyond. The section links point to the parts of the book it draws on.