Converts value to an integer. Runs through _.toFinite, then drops the fractional part toward zero (like Math.trunc). Part of Lodash 4.x Lang (since 4.0.0).
Pass the value you want to inspect or convert. Read the return type carefully before you use the result.
Syntax
Call _.toInteger. Start with this line.
Lodash
_.toInteger(value)
Call
What it does
_.toInteger(value)
Primary signature.
Prefer import toInteger from "lodash/toInteger" when you want a smaller bundle.
Library declarations
Lodash
_.toInteger(value)
Parameters
Parameter
Description
value
Required. Any value to convert
Return Value
Return Value
Description
*
Integer number (no fraction)
Lodash Examples
Example 1 — Official: Number and Numeric String
Decimals become whole numbers; strings parse first.
Parse fail. Junk becomes NaN → toFinite maps to 0.
null. Ends up as 0.
Trim. Whitespace around digits is fine.
Caution. Zero may hide bad input — validate when 0 is meaningful.
Compatibility
Browser & Runtime Support
_.toInteger is a Lodash 4.x Lang helper (since 4.0.0). It runs anywhere Lodash runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install lodash. Closest native cousin is Math.trunc(Number(value)), but Lodash also applies toFinite clamping and soft-fails bad strings to 0.
✓ Stable · Lodash 4.x
_.toInteger()
Available in [email protected] full builds and the lodash/toInteger modular import. Works in evergreen browsers and current Node LTS when Lodash is installed.
100%With Lodash 4.x
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.jsSupported · Server runtime
Supported
Android WebViewSupported · Modern WebView
Full support
_.toIntegerLodash 4.x+
Bottom line: Safe for production once Lodash is loaded. Prefer import toInteger from "lodash/toInteger" for smaller builds. Ideal for indexes, counters, and whole-number form sanitizing.
Frequently Asked Questions
_.toInteger(value) converts value to a finite number, then removes the fractional part toward zero — like Math.trunc, not Math.floor.
No. For negatives they differ: _.toInteger(-42.7) is -42; Math.floor(-42.7) is -43.
toInteger runs toFinite first, then drops the fraction. So Infinity still becomes Number.MAX_VALUE.
MIN_VALUE is about 5e-324. After conversion, removing the fractional part leaves 0.
toSafeInteger also clamps into the safe integer range (±(2^53−1)). toInteger does not — Infinity becomes MAX_VALUE.
Use import toInteger from "lodash/toInteger" or require("lodash/toInteger") for tree-shaking. Full build: import _ from "lodash" then _.toInteger.