Increment number in jQuery 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?

DEMO

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); // -&gt; result: "0001"

console.log("015-" + res + "-" + incrementvalue);
var data = [{"code":"456100010011","incrementingnumber":"015-0011-00001"}];

var code = data[0].code,
    inc = data[0].incrementingnumber;
var inc1 = inc.split('-');
inc1[2] = ('00000' + ++inc1[2]).slice(-5);

document.write(inc1.join('-'));




You don't need the code.slice, but you'd still need to split your incrementingnumber value.