1. Padding string
ES7 introduced the function of full length of string complement. If a string does not have a specified length, it is complete at the head or tail.
String.prototype.padStart (MaxLength, fillstring= ")
The method is populated with fillstring before the string until the string length is maxLength.
String.prototype.padEnd (MaxLength, fillstring= ")
The method is populated with fillstring after the string , until the string length is maxLength.
To populate the string with the specified character, for example:
1) The length of the string is less than maxlength, and the specified character is populated before the string.
' Hello '. Padstart (, ' a '); // back to "Aaaaahello"
Do time countdown function, if the number is a single number, you can convert it to a string type, and then fill the front 0.
string (num). Padstart (2,0)string(// output 'down ' string (one). Padstart (2,0) // output ' one '
2) If Fillstring is omitted, a separate space string (") is used instead.
//Return " Hello"
3) If the length of the string is greater than or equal to MaxLength, the original string is returned.
' Hello '. Padstart (5, ' a '); // return "Hello"
Some of the more frequently used methods in JavaScript development