padEnd method
The padEnd method pads the end
of the current string until it reaches
the length specified in the first
parameter. The second optional parameter
specifies the string with which we want
to pad the current.
Syntax
string.padEnd(string length, [string for padding]);
Example
Let's pad a string so that its
length is 10 characters:
let res = 'abcdef'.padEnd(10);
console.log(res);
The code execution result:
'abcdef '
Example
If we pass more characters to the optional parameter than required, the extra ones will be discarded and will not complete the string.
let res = 'abc'.padEnd(5, 'defg');
console.log(res);
The code execution result:
'abcde'
Example
Let's set the first parameter to a number less than the length of the current string:
let res = 'abcde'.padEnd(1);
console.log(res);
As a result of executing the code, the entire string will be returned:
'abcde'