-1

How do I create a " 00000001" type number format or string in javascript, like " 00000001 0000002 00000003 ... 000000123 " and so on, can you please help me??

Calin Onaca
  • 165
  • 1
  • 14

1 Answers1

0

You can use str.padStart(targetLength [, padString]):

console.log('0'.padStart(10, '0'));
console.log('01234'.padStart(10, '0'));
console.log('0123456789'.padStart(10, '0'));
console.log('0123456789ABCDEF'.padStart(10, '0'));
.as-console-wrapper {
  max-height: none;
}
Danziger
  • 16,123
  • 4
  • 41
  • 70