JS Built-ins
StringString.prototype.padEndbeginner

String.prototype.padEnd() β€” basic padding

πŸ“– Usage Example
'5'.padEnd(3, '0')       // β†’ '500'
'hello'.padEnd(8, '-')   // β†’ 'hello---'
'hi'.padEnd(2)           // β†’ 'hi'

Use padEnd() to pad the end of a string with a fill character until it reaches the target length.

String.prototype.padEnd()

str.padEnd(targetLength, padString?) pads the end of str with padString (default: space) until the total length reaches targetLength.

Challenge: Implement padRight(str, len) that pads with spaces to the given length.

padRight('hi', 5) // β†’ 'hi   '
πŸ’‘ Hints (1)
  • β€’ `.padEnd()` adds padding to the end (right side) of the string.