In JavaScript, you can use the padStart()
method to achieve the same functionality as the LPAD function in other programming languages. The padStart()
method allows you to add padding (specified by a string) to the beginning of a string, until it reaches a specified length. Here’s an example of how you could use it:
let originalString = '1234';
let paddedString = originalString.padStart(10, '0');
console.log(paddedString);
This will output:
000000001234
In this example, the originalString
is padded with 0
s until its length reaches 10
.
+ There are no comments
Add yours