Number.parseInt()
method parses a string argument and returns an integer of the specified radix or base.
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
Number.parseInt(string,[ radix])
string
ToString
abstract operation. Leading whitespace in this argument is ignored.
radix
可选
2
and
36
that represents the
radix
(the base in mathematical numeral systems) of the
string
. Be careful—this does
not
default to
10
!
An integer parsed from the given
string
.
若
radix
<
2
or bigger than
36
, and the first non-whitespace character cannot be converted to a number,
NaN
被返回。
if (Number.parseInt === undefined) {
Number.parseInt = window.parseInt
}
This method has the same functionality as the global
parseInt()
函数:
Number.parseInt === parseInt // true
and is part of ECMAScript 2015 (its purpose is modularization of globals). Please see
parseInt()
for more detail and examples.
| 规范 |
|---|
|
ECMAScript (ECMA-262)
The definition of 'Number.parseInt' in that specification. |
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
parseInt
|
Chrome 34 | Edge 12 | Firefox 25 | IE No | Opera 21 | Safari 9 | WebView Android ≤37 | Chrome Android 34 | Firefox Android 25 | Opera Android 21 | Safari iOS 9 | Samsung Internet Android 2.0 | nodejs 0.12 |
完整支持
不支持
Number
object it belongs to.
parseInt()
方法。
Number
Number.isFinite()
Number.isInteger()
Number.isNaN()
Number.isSafeInteger()
Number.parseFloat()
Number.parseInt()
Number.prototype.toExponential()
Number.prototype.toFixed()
Number.prototype.toLocaleString()
Number.prototype.toPrecision()
Number.prototype.toSource()
Number.prototype.toString()
Number.prototype.valueOf()
Function
Object
Object.prototype.__defineGetter__()
Object.prototype.__defineSetter__()
Object.prototype.__lookupGetter__()
Object.prototype.__lookupSetter__()
Object.prototype.hasOwnProperty()
Object.prototype.isPrototypeOf()
Object.prototype.propertyIsEnumerable()
Object.prototype.toLocaleString()
Object.prototype.toSource()
Object.prototype.toString()
Object.prototype.valueOf()
Object.setPrototypeOf()