I have this number returned from an Ajax request: 015-0011-00001. I want to increment the last part of the number (00001) on document load. What I did was get the last number and increment it then combine the numbers again. Is there a cleaner way of incrementing this number without slicing the number into many parts?
var data = [{"code":"456100010011","incrementingnumber":"015-0011-00001"}];
var code = data[0].code;
var inc = data[0].incrementingnumber;
var res = code.slice(-4);
var inc1 = inc.slice(-4);
//alert(inc1);
var inc2 = parseInt(inc1) + 1;
var incrementvalue = ("00000" + inc2).slice(-5); // -> result: "0001"
console.log("015-" + res + "-" + incrementvalue);