Lodash _.parseInt() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
String

Definition

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.

Syntax

Call _.parseInt. Start with this line.

Lodash
_.parseInt(string, [radix])
CallWhat 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.

Library declarations
Lodash
_.parseInt(string, [radix])

Parameters

ParameterDescription
stringRequired. Value to parse
radixOptional. Base 2–36; auto 10 (or 16 for hex-looking strings)

Return Value

Return ValueDescription
*Integer, or NaN

Lodash Examples

Example 1 — Official: Parse '08'

Leading zeros are fine in base 10.

Lodash
_.parseInt("08");
// → 8
Try It Yourself

How It Works

  1. Input. String "08".
  2. Radix. Defaults to decimal 10.
  3. Result. Integer 8 — not an octal value.
  4. Docs. Matches the official first example.

Example 2 — Explicit Hex Radix

Pass 16 for hexadecimal strings.

Lodash
_.parseInt("FF", 16);
// → 255

_.parseInt("1010", 2);
// → 10
Try It Yourself

How It Works

  1. Hex. Radix 16 reads digits 0–9 and A–F.
  2. Binary. Radix 2 reads only 0 and 1.
  3. Tip. Always pass radix when the base is known.
  4. Range. Valid radix values are 2 through 36.

Example 3 — Map an Array of Strings

Official docs map example — use a unary wrapper so index ≠ radix.

Lodash
_.map(["6", "08", "10"], function (value) {
  return _.parseInt(value);
});
// → [6, 8, 10]
Try It Yourself

How It Works

  1. Each. Every string is parsed on its own.
  2. Unary. Only value is passed — index never becomes radix.
  3. Result. [6, 8, 10] as in the official intent.
  4. Also. _.map(arr, _.ary(_.parseInt, 1)) is another safe form.

Example 4 — Native map(parseInt) Pitfall

Array map passes the index as the second argument.

Lodash
["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)
Try It Yourself

How It Works

  1. Callback. map calls fn(value, index, array).
  2. Radix. parseInt treats index as radix.
  3. Broken. Middle and last values parse wrong.
  4. Fix. Use s => _.parseInt(s) or pass radix explicitly.

Example 5 — Invalid Input → NaN

Non-numeric starts become NaN; partial prefixes still parse.

Lodash
_.parseInt("abc");
// → NaN

_.parseInt("12px");
// → 12
Try It Yourself

How It Works

  1. abc. No leading digits → NaN.
  2. 12px. Reads 12, then stops at p.
  3. Check. Use Number.isNaN when input may be junk.
  4. Strict. Prefer validating the whole string if partial parse is wrong for your case.

Browser & Runtime Support

_.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.

✓ Stable · Lodash 4.x

_.parseInt()

Available in [email protected] full builds and the lodash/parseInt modular import. Works in evergreen browsers and current Node LTS when Lodash is installed.

100% With Lodash 4.x
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
_.parseInt Lodash 4.x

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.

Frequently Asked Questions

_.parseInt(string, [radix]) converts string to an integer of the given radix. Official: _.parseInt('08') → 8. It aligns with the ES5 parseInt behavior.
If radix is undefined or 0, Lodash uses 10 unless the string looks hexadecimal (e.g. 0x…), in which case 16 is used.
With radix 10 (the usual default), leading zeros do not mean octal. You get decimal 8, not an octal parse.
Pass radix 16: _.parseInt('FF', 16) → 255. Strings like '0x10' can also resolve as hex when radix is auto.
Native map passes (value, index, array). parseInt treats index as radix, so ['6','08','10'].map(parseInt) → [6, NaN, 2]. Prefer a unary wrapper: s => _.parseInt(s).
_.parseInt stops at the first non-digit (after optional sign/prefix) and returns an integer. _.toNumber aims for a full Number conversion (floats included).

Next: _.repeat()

Repeat a string a given number of times.

_.repeat() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

10 people found this page helpful