EN
JavaScript - String padEnd() method example
0 points
xxxxxxxxxx
1
const text = 'A';
2
3
console.log(text.padEnd(1, '*')); // A
4
console.log(text.padEnd(2, '*')); // A*
5
console.log(text.padEnd(3, '*')); // A**
Syntax |
|
Parameters |
|
Result | A String of the specified maxLength with the fillString applied at the end of the current string. |
Description | The method pads the current string with a given string (possibly repeated) so that the resulting string reaches a given length. The padding is applied from the end (right) of the current string. |
In this example, we pad a number
to keep only the first 3 digits.
xxxxxxxxxx
1
const number = '123456789';
2
const first3Digits = number.slice(6);
3
const maskedNumber = first3Digits.padEnd(number.length, '*');
4
5
console.log(maskedNumber);
Output:
xxxxxxxxxx
1
789******