String padEnd()
str.padEnd(n, pad)
str
is a stringn
is an integerpad
is a string
padEnd() method makes a copy of the string str
, pads given pad
string to the end of calling string str
such that the length of resulting string is n
, and returns the resulting string. original string str
is not modified. If n
is less than length of original str
, then padEnd() returns original string str
as is.
Examples
1. pad string at end
let name = 'apple';
let output = name.padEnd(10, '#');
console.log(output);
2. n
is less than length of original string
let name = 'apple';
let output = name.padEnd(4, '#');
console.log(output);