string.padEnd(length [, pad_string]);
Parameters or Arguments
length The favored length of the ensuing string after it has been padded. pad_string Optional. It is the special string to pad to the quit of string. If this parameter is not provided, the padEnd() approach will use a house as the pad character.
The padEnd() approach returns a string that has been padded at the cease with the precise string to the preferred length.
The padEnd() technique does now not exchange the fee of the authentic string.
var totn_string = 'TechOnTheNet'; console.log(totn_string.padEnd(20,'A'));
In this example, we have declared a variable known as totn_string that is assigned the string price of ‘TechOnTheNet’. We have then invoked the padEnd() approach of the totn_string variable to pad the end of totn_string with ‘A’ till it is the preferred size of 20 characters.
We have written the output of the padEnd() approach to the internet browser console log, for demonstration purposes, to exhibit what the padEnd() technique returns.
The following will be output to the web browser console log:
As you can see, the padEnd() method brought eight ‘A’ characters to the give up of ‘TechOnTheNet’ to make the ensuing string ‘TechOnTheNetAAAAAAAA’ 20 characters in length.
Specifying Multiple Characters as the Pad String
Finally, let’s see what takes place if you specify a pad_string parameter for the padEnd() approach that is multiple characters (and not simply a single character).
var totn_string = 'TechOnTheNet'; console.log(totn_string.padEnd(16,'xyz'));
The following will be output to the internet browser console log:
In this example, we have invoked the padEnd method() with a pad_string of ‘xyz’ and a desired size of 16 characters. The padEnd() method lower back the string fee of ‘TechOnTheNetxyzx’.
Notice that the ensuing string ended with the ‘x’ persona and no longer the ‘z’ character. This took place because the sequence of characters in the pad_string persisted to repeat till the ensuing string was the preferred size of sixteen characters. In this case, it stopped repeating at the ‘x’ character.