padStart()
noun
say it: “PAD START” /pæd stɑːrt/
A JavaScript string method that adds characters to the front of text until it reaches a given length, such as '7'.padStart(3, '0') giving '007'.
What is padStart() in JavaScript?
padStart() — A string method that adds a character to the start of text until it reaches the length you ask for, such as turning bib number 7 into 007. It works on text, so turn a number into a string first.
const bib = 7;
console.log(String(bib).padStart(3, '0')); // 007
In a sentence
- “String(seconds).padStart(2, '0') turned 5 seconds into 05, so the timer read 3:05.”
Level: Apprentice · More JavaScript terms at this level
Updated