Number.parseInt
Number.parseInt()方法可以根据给定的进制数把一个字符串解析成整数。
语法
Number.parseInt(string,[ radix ])参数
string要解析的值。如果string参数不是一个字符串,那么它将被转换为一个字符串(使用ToString抽象操作)。字符串参数中的空白字符将被忽略。radix表示上述字符串的基数(数学数字系统中的基数)的2到36之间的整数。指定10人类通常使用的十进制数字系统。始终指定此参数以消除读者的困惑并保证可预测的行为。没有指定基数时,不同的实现会产生不同的结果,通常默认值为10。
返回值
从给定字符串解析的整数 如果第一个字符不能转换为数字,则返回NaN。
描述
该方法和全局的 parseInt()函数是同一个函数:
Number.parseInt === parseInt; // true请移步全局函数 parseInt()页面查看更多的解释和示例。
Polyfill
if (Number.parseInt === undefined)
Number.parseInt = window.parseInt;规范
Specification | Status | Comment |
|---|---|---|
ECMAScript 2015 (6th Edition, ECMA-262)The definition of 'Number.parseInt' in that specification. | Standard | Initial definition. |
ECMAScript Latest Draft (ECMA-262)The definition of 'Number.parseInt' in that specification. | Living Standard | |
浏览器兼容性
Feature | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|---|
Basic Support | (Yes) | (Yes) | 25 | No | (Yes) | 9 |
Feature | Android | Chrome for Android | Edge mobile | Firefox for Android | IE mobile | Opera Android | iOS Safari |
|---|---|---|---|---|---|---|---|
Basic Support | (Yes) | (Yes) | (Yes) | 25 | No | (Yes) | 9 |
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com

