Maybe a little late, but I want to add my 2 cents.
if your ALWAYS string represents a number, with possible leading zeros, you can simply pass the string to a number using the "+" operator.
eg.
x= "00005"; alert(typeof x); //"string" alert(x);// "00005" x = +x ; //or x= +"00005"; //do NOT confuse with x+=x, which will only concatenate the value alert(typeof x); //number , voila! alert(x); // 5 (as number)
if your string does not represent a number and you only need to remove 0, use other solutions, but if you need them only as a number, this is the shortest way.
and FYI you can do the opposite, force the numbers to act like strings if you combine an empty string into them, for example:
x = 5; alert(typeof x); //number x = x+""; alert(typeof x); //string
hope this helps someone
DiegoDD Nov 05 '13 at 0:58 2013-11-05 00:58
source share