JS: String.prototype.padStart
New in JS2017.
str.padStart(n)
-
Add spaces in front so the length is n. Return the new string.
"x".padStart(3) === " x"
str.padStart(n, padstr)
-
Use padStr to pad.
console.log( "x".padStart(3, "0") === "00x", "x".padStart(4, "ab") === "abax", );
/* no padding happens, because "😂" is already length 2 */ console.log("😂".padStart(2, "x") === "😂"); /* 😂 name: FACE WITH TEARS OF JOY codepoint decimal: 128514 codepoint hexadecimal: 1f602 UTF8 encoding: F0 9F 98 82 Utf16 encoding: D8 3D DE 02 */
Note: "😂".length === 2
〔see JS: String Code Unit〕
JS String.prototype
- JS: String.prototype.constructor
- JS: String.fromCharCode
- JS: String.prototype.concat
- JS: String.prototype.repeat
- JS: String.prototype.trim
- JS: String.prototype.trimStart
- JS: String.prototype.trimEnd
- JS: String.prototype.padStart
- JS: String.prototype.padEnd
- JS: String.prototype.slice
- JS: String.prototype.substring
- JS: String.prototype.substr
- JS: String.prototype.indexOf
- JS: String.prototype.lastIndexOf
- JS: String.prototype.includes
- JS: String.prototype.startsWith
- JS: String.prototype.endsWith
- JS: String.prototype.search
- JS: String.prototype.match
- JS: String.prototype.matchAll
- JS: String.prototype.replace
- JS: String.prototype.split
- JS: String.prototype.toLowerCase
- JS: String.prototype.charAt
- JS: String.prototype.charCodeAt
- JS: String.prototype.codePointAt