Wallflower Wallflower - 10 months ago 40
Javascript Question

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

If I have the string

how can I remove the PK and leading 0s to get just

Answer Source

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