Example 1 — Official: Parse '08'
Leading zeros are fine in base 10.
_.parseInt("08");
// → 8 How It Works
- Input. String
"08". - Radix. Defaults to decimal 10.
- Result. Integer
8— not an octal value. - Docs. Matches the official first example.

Convert a string to an integer of a given radix (base). Part of Lodash String (stable — not deprecated). Leading zeros are fine in base 10 — '08' becomes 8.
Pass the string and options shown below. Check the return type before you chain another helper.
Call _.parseInt. Start with this line.
_.parseInt(string, [radix]) | Call | What it does |
|---|---|
_.parseInt(string, [radix]) | Primary signature. |
_.parseInt(string) | Transform or inspect a string. |
Prefer import parseInt from "lodash/parseInt" when you want a smaller bundle.
_.parseInt(string, [radix]) | Parameter | Description |
|---|---|
| string | Required. Value to parse |
| radix | Optional. Base 2–36; auto 10 (or 16 for hex-looking strings) |
| Return Value | Description |
|---|---|
| * | Integer, or NaN |
'08'Leading zeros are fine in base 10.
_.parseInt("08");
// → 8 "08".8 — not an octal value.Pass 16 for hexadecimal strings.
_.parseInt("FF", 16);
// → 255
_.parseInt("1010", 2);
// → 10 16 reads digits 0–9 and A–F.2 reads only 0 and 1.Official docs map example — use a unary wrapper so index ≠ radix.
_.map(["6", "08", "10"], function (value) {
return _.parseInt(value);
});
// → [6, 8, 10] value is passed — index never becomes radix.[6, 8, 10] as in the official intent._.map(arr, _.ary(_.parseInt, 1)) is another safe form.map(parseInt) PitfallArray map passes the index as the second argument.
["6", "08", "10"].map(parseInt);
// → [6, NaN, 2]
// Why?
// parseInt("6", 0) → 6
// parseInt("08", 1) → NaN (radix 1 invalid)
// parseInt("10", 2) → 2 (binary) map calls fn(value, index, array).parseInt treats index as radix.s => _.parseInt(s) or pass radix explicitly.NaNNon-numeric starts become NaN; partial prefixes still parse.
_.parseInt("abc");
// → NaN
_.parseInt("12px");
// → 12 NaN.12, then stops at p.Number.isNaN when input may be junk._.parseInt is a Lodash String helper available in 4.x, documented as aligning with ES5 parseInt. It runs anywhere Lodash runs — modern browsers (via CDN or bundle) and Node.js / Bun / Deno with npm install lodash. Native parseInt is universal; Lodash helps in pipelines and consistent trimming/coercion.
Available in [email protected] full builds and the lodash/parseInt modular import. Works in evergreen browsers and current Node LTS when Lodash is installed.
Bottom line: Safe for production once Lodash is on the page or in your bundle. Prefer import parseInt from "lodash/parseInt" for smaller builds. Always pass radix in app code when the base is known.
Repeat a string a given number of times.
CODETOFUN NEWS
Get the latest IT news, programming updates, and technology trends directly on your phone.
Your daily dose of tech, straight to your feed.
10 people found this page helpful