Remove leading zeros from a number in JavaScript
How to remove leading zeros from a number like 020?
The simplest way is to use parseInt() with radix 10 when your number is in string format.
Advertisements
parseInt(number, 10)
10 is the decimal base in mathematical numeral systems. Decimal radix removes the leading zeros when parsed.
console.log(parseInt('015', 10)); //15
Another way is to use string replace replace method.
console.log('015'.replace(/^0+/, '')); //15