parseInteger()
parseInteger(
str,radix):number
Parses a string into an integer of the specified radix.
DEPRECATED
Use parseInt() directly instead.
Parametersโ
str: string | null | undefinedโ
The string to parse.
radix: number = 10โ
The radix (base) to use for parsing. Defaults to 10.
Returns: numberโ
The parsed integer, or NaN if parsing fails.
See Alsoโ
Sinceโ
2.0.0
Also known asโ
parseInt (Lodash, es-toolkit) ยท โ (Remeda, Radashi, Ramda, Effect, Modern Dash, Antfu)
Exampleโ
// โ Deprecated approach
parseInteger('42'); // => 42
parseInteger('10', 2); // => 2 (binary)
parseInteger('ff', 16); // => 255 (hex)
// โ
Recommended approach
parseInt('42', 10); // => 42
parseInt('10', 2); // => 2 (binary)
parseInt('ff', 16); // => 255 (hex)
How it works?โ
Parses string to integer with radix.
Deprecated: Use parseInt() directly.
Native Equivalentโ
// โ parseInteger(str, 10)
// โ
parseInt(str, 10)
Use Casesโ
Parse integer ๐โ
Parse string to integer.
parseInt('42', 10); // 42
Convert user inputโ
Parse form input to number.
const quantity = parseInt(input, 10) || 0;