Number.parseInt()
方法可以根据给定的进制数把一个字符串解析成整数。
Number.parseInt(string[, radix])
// radix为指定基数,说明字符串为多少进制的数字表示。
let strObj = '0110';
console.log(Number.parseInt(strObj, 2)); // 6
console.log(Number.parseInt(strObj, 10)); // 110
该方法和全局的 parseInt()
函数是同一个函数:
Number.parseInt === parseInt; // true
请移步全局函数 parseInt()
页面查看更多的解释和示例。
Number.parseInt = parseInt;
规范名称 | 规范状态 | 备注 |
---|---|---|
ECMAScript 2015 (6th Edition, ECMA-262) Number.parseInt |
Standard | 初始规范. |
ECMAScript Latest Draft (ECMA-262) Number.parseInt |
Draft |
本页面中的兼容性表通过结构化的数据自动生成. 如果你想为结构化的数据贡献信息, 请通过 https://github.com/mdn/browser-compat-data 这个 GitHub 仓库提交 pull request 进行贡献.
Desktop | Mobile | Server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
parseInt | Chrome Full support Yes | Edge Full support 12 | Firefox Full support 25 | IE No support No | Opera Full support Yes | Safari Full support 9 | WebView Android Full support Yes | Chrome Android Full support Yes | Edge Mobile Full support Yes | Firefox Android Full support 25 | Opera Android Full support Yes | Safari iOS Full support 9 | Samsung Internet Android Full support Yes | nodejs Full support 0.12 |
Number()
parseInt()
函数