Example 1 — Basic decimal parse
Convert '42' to the integer 42.
const parsed = _.parseInt("42", 10);
console.log(parsed);
// -> 42 How It Works
Radix 10 parses base-ten digits.

By the end of this tutorial, you’ll use Lodash’s _.parseInt() confidently in real string workflows.
Call _.parseInt(string, [radix]).
Specify base 10, 16, etc. explicitly.
Detect and handle invalid input.
Parse string collections in one line.
Integers only—no decimals.
Validate before math operations.
_.parseInt()?_.parseInt() parses a string into an integer. It wraps the native parseInt() with lodash’s consistent API so you can pass it to _.map() and other functional helpers without binding issues.
Always pass an explicit radix (usually 10) when parsing user input—_.parseInt('08', 10) avoids legacy octal surprises in older environments.
_.parseInt(string, [radix]) string — The string to parse into an integer.radix — Optional base (2–36); defaults to 10 in lodash.Return value — Integer or NaN when parsing fails.Partial parse — Stops at the first non-numeric character (like native parseInt).Functional use — Works as a callback: _.map(arr, _.parseInt).import parseInt from "lodash/parseInt";
const value = _.parseInt("42", 10);
// -> 42 | Task | Code pattern | Result |
|---|---|---|
| Decimal | _.parseInt('42', 10) | Integer 42 |
| Hex | _.parseInt('FF', 16) | Integer 255 |
| Map array | _.map(['1','2'], _.parseInt) | [1, 2] |
| Invalid | _.parseInt('abc') | NaN |
| Strip symbol | _.parseInt('$50'.slice(1), 10) | 50 |
| Native alt | parseInt(str, 10) | Built-in global |
NoReturns number
10Decimal base
On failureCheck with isNaN
parseInt()Same algorithm
string RequiredText to parse; leading whitespace trimmed.
_.parseInt('42', 10)radix OptionalInteger base between 2 and 36.
_.parseInt('FF', 16)return value NumberParsed integer or NaN.
const n = _.parseInt(input, 10)callback PatternUse unbound with _.map for string arrays.
_.map(rows, _.parseInt)Practical _.parseInt() patterns with copy-ready code and interactive Try It Yourself labs.
Parse a simple numeric string.
Convert '42' to the integer 42.
const parsed = _.parseInt("42", 10);
console.log(parsed);
// -> 42 Radix 10 parses base-ten digits.
Radix handling and batch parsing.
Convert FF with radix 16.
const parsed = _.parseInt("FF", 16);
console.log(parsed);
// -> 255 Radix 16 interprets hex digits.
Parse multiple numeric strings at once.
const strings = ["10", "20", "30"];
const numbers = _.map(strings, value => _.parseInt(value, 10));
console.log(numbers);
// -> [10, 20, 30] Lodash parseInt works cleanly inside map callbacks.
Detect NaN from non-numeric strings.
const result = _.parseInt("abc", 10);
console.log(Number.isNaN(result));
// -> true Always validate before using parsed values in math.
Parse a price after removing $.
const price = _.parseInt("$50".replace("$", ""), 10);
// -> 50 Clean non-digit prefixes before parsing.
Native parseInt comparison.
Global parseInt behaves the same for basic cases.
const str = "42";
const native = parseInt(str, 10);
const lodash = _.parseInt(str, 10);
// both -> 42 Use lodash when you need the functional callback style.
| Topic | _.parseInt | parseInt() | Number() | parseFloat() |
|---|---|---|---|---|
| Input | String | String | Any | String |
| Radix | Yes | Yes | No | No |
| Fractions | Truncates | Truncates | Preserves | Preserves |
| NaN on bad | Yes | Yes | Yes | Yes |
| Best for | Integer strings | Same | Coercion | Decimals |
_.parseInt() WorksLodash passes the string to the parsing logic.
Base defaults to 10 when omitted.
Reads numeric prefix; stops at first invalid char.
Number or NaN returned.
radix for user-facing parsing.NaN when no valid digits are found.'42px' -> 42)._.isNaN() or Number.isNaN() to detect failed parses.parseFloat() or Number()._.map(strings, _.parseInt)._.parseInt() gives you reliable integer parsing with lodash’s functional API. Specify radix explicitly, validate with isNaN, and use it to transform string collections into numbers.
Pass 10 explicitly.
BasicsValidate failures.
SafetyCallback-friendly API.
PatternRadix 16 for hex.
AdvancedNot for decimals.
LimitPassing _.parseInt directly to _.map() works because lodash’s version is designed as a consistent callback—unlike array.map(parseInt) which passes index as radix.
Open Try It, run the examples, and experiment with your own strings.
6 people found this page helpful