Wallflower Wallflower - 2 months ago 7
Javascript Question

JavaScript get number from string that contain '0' in front of number

If I have the string

"PK000019"
how can I remove the PK and leading 0s to get just
"19"
?

Answer

Is this something like what you're looking for?

var code = "PK000019";
var code_num = parseInt(code.substr(2), 10); //returns 19

You can get the full product code back from the number like so:

var code_num = 19;
var code = "PK" + ("00000" + code_num).slice(-6); //returns PK000019