0

How to change string to number and plus 1 with 000 in front of it ( I'm using javascirpt node JS)

ex 
const string = "0009"
const newString =  string + 1

I want outout 0010

this is what I try

const newString = parseInt(string)+1
const ans = '000' + newString

the problem is output is 00010 I want 0010

if more number 0 will less like 0999 or 9999

Akw
  • 91
  • 2
  • 11
  • Does this answer your question? [How can I pad a value with leading zeros?](https://stackoverflow.com/questions/1267283/how-can-i-pad-a-value-with-leading-zeros) – Brian McCutchon Oct 07 '20 at 04:22
  • @BrianMcCutchon yes thank you I try to find it but I dont know the key word thank you – Akw Oct 07 '20 at 04:27

1 Answers1

0

Try it

const newString = parseInt(string)+1
const ans = ('0000'+newString).slice(-4);
John V
  • 875
  • 6
  • 12