I know it is related to Remove first character from a string if it is a comma but in this case that solution doesn't work for me. Maybe its because now I'm dealing with a number. Simply I want javascript to remove 0
from 08
but don't touch 10
; only remove 0
when it is the first character.
This solution doesn't work: replace(/^0/, "")
You can try this:
alert("08".replace(/^0+/, ''));
And if you are dealing with numbers then you can use parseInt() function.
Easy way with regex :
^0+(?!$)
and feel free to use String replaceFirst
function.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.