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
Advertisement
Answer
Try it
const newString = parseInt(string)+1 const ans = ('0000'+newString).slice(-4);