Pad a string with "0" until it reaches the length 4:
let text = "5";
let padded = text.padStart(4,"0");
Pad a string with "x" until it reaches the length 4:
let text = "5";
let padded = text.padStart(4,"x");
The padStart()
method pads a string from the start.
The padStart()
method pads a string with another string (multiple times) until it reaches a given length.
let numb = 5;
let text = numb.toString();
let padded = text.padStart(4,"0");
string.padStart(length, string)
Parameters Parameter Description length Required.padStart()
is a JaveScript 2017 feature.
ES 2017 is supported in all modern browsers since September 2017:
Chrome 58 Edge 15 Firefox 52 Safari 11 Opera 45 Apr 2017 Apr 2017 Mar 2017 Sep 2017 May 2017Track your progress - it's free!
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4