Javascript, why treated as octal

前端 未结 6 527
我在风中等你
我在风中等你 2020-12-06 20:58

I\'m passing as parameter an id to a javascript function, because it comes from UI, it\'s left zero padded. but it seems to have (maybe) \"strange\" behaviour?



        
6条回答
  •  死守一世寂寞
    2020-12-06 21:44

    Unless you can intercept a string version of this number, you're out of luck.

    That being said, if you can get a string version of your octal (calling toString() won't help), this will work:

    parseInt(variable_string.replace(/^0+/, ''), 10);
    

提交回复
热议问题