0

I have function that needs to return a String+ number . the number can be from 0 to 1000 . But I always want number to be in format 0000 ,0001 ,0002,0116 etc .. How can I do It ? Thanks

1 Answers1

1

You can do that using padStart method. Hope this helps.

const padWithZeros = (number) => number.toString().padStart(4, 0)

console.log( padWithZeros(1) )
console.log( padWithZeros(10) )
console.log( padWithZeros(121) )
lankovova
  • 1,396
  • 8
  • 15