This is a new technology, part of the ECMAScript 2015 (ES6) standard.
This technology's specification has been finalized, but check the compatibility table for usage and implementation status in various browsers.
El mètode Number.parseInt()
interpreta un argument string i retorna un nombre sencer de la base especificada.
Sintaxi
Number.parseInt(string[, radix])
Paràmetres
string
- The value to parse. If the
string
argument is not a string, then it is converted to a string (using theToString
abstract operation). Leading whitespace in the string argument is ignored. radix
- An integer between 2 and 36 that represents the radix (the base in mathematical numeral systems) of the above mentioned string. Specify
10
for the decimal numeral system commonly used by humans. Always specify this parameter to eliminate reader confusion and to guarantee predictable behavior. Different implementations produce different results when a radix is not specified, usually defaulting the value to 10.
Descripció
Aquest mètode és exactament la mateixa funció que la funció global parseInt()
:
Number.parseInt === parseInt; // true
i és part de l'ECMAScript 6 (el seu propòsit és la modularització de les globals). Vegeu jsxref("Global_Objects/parseInt", "parseInt()")}} per a més detalls i exemples.
Polyfill
Number.parseInt = parseInt;
Especificacions
Especificació | Estat | Comentaris |
---|---|---|
ECMAScript 2015 (6th Edition, ECMA-262) The definition of 'Number.parseInt' in that specification. |
Standard | Definició inicial. |
Compatibilitat amb navegadors
We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!
Característica | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Suport bàsic | (Yes) | 25 (25) | No support | (Yes) | No support |
Característica | Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Suport bàsic | No support | 25 (25) | No support | No support | No support |
Vegeu també
- L'objecte
Number
al que pertany. - La funció global
parseInt()
.