Lodash _.isInteger() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Lang

Definition

Checks if value is an integer — a finite primitive number with no fractional part. Based on Number.isInteger. Since Lodash 4.0.0.

Pass the value you want to inspect or convert. Read the return type carefully before you use the result.

Syntax

Call _.isInteger. Start with this line.

Lodash
_.isInteger(value)
CallWhat it does
_.isInteger(value)Primary signature.

Prefer import isInteger from "lodash/isInteger" when you want a smaller bundle.

Library declarations
Lodash
_.isInteger(value)

Parameters

ParameterDescription
valueRequired. The value to check

Return Value

Return ValueDescription
*true if integer, else false

Lodash Examples

Example 1 — Official: Basics

Integers pass; MIN_VALUE, Infinity, and strings fail.

Lodash
_.isInteger(3);
// → true

_.isInteger(Number.MIN_VALUE);
// → false

_.isInteger(Infinity);
// → false

_.isInteger("3");
// → false
Try It Yourself

How It Works

  1. 3 is a whole primitive number → true.
  2. MIN_VALUE is a tiny positive float → false.
  3. Infinity is not finite → false.
  4. "3" is a string — no coerce → false.

Example 2 — Floats vs 3.0

A fractional part fails; 3.0 is still the integer 3.

Lodash
_.isInteger(3.14);
// → false

_.isInteger(3.0);
// → true

_.isFinite(3.14);
// → true   // finite, but not an integer
Try It Yourself

How It Works

  1. 3.14 has a fraction → not an integer.
  2. 3.0 equals 3 in IEEE math → integer.
  3. isFinite(3.14) can still be true.
  4. Pick isInteger when you need whole numbers only.

Example 3 — Negatives and -0

Negative whole numbers count; -0 is still an integer.

Lodash
_.isInteger(-5);
// → true

_.isInteger(-0);
// → true

_.isInteger(-3.5);
// → false
Try It Yourself

How It Works

  1. -5 is a whole number → true.
  2. -0 is integer zero with a sign bit → true.
  3. -3.5 has a fraction → false.
  4. Sign does not matter — only the fractional part does.

Example 4 — Parse Strings, Then Check

Convert form input, then require an integer.

Lodash
function asInteger(input) {
  var n = Number(input);
  return _.isInteger(n) ? n : null;
}

asInteger("42");
// → 42

asInteger("3.5");
// → null

asInteger("oops");
// → null
Try It Yourself

How It Works

  1. Number(input) converts the string deliberately.
  2. isInteger rejects floats and NaN.
  3. "42" → integer → return 42.
  4. Bad / float inputs → null.

Example 5 — Array Index Guard

Allow only non-negative integers before indexing.

Lodash
function at(arr, index) {
  if (!_.isInteger(index) || index < 0) {
    return undefined;
  }
  return arr[index];
}

at(["a", "b", "c"], 1);
// → "b"

at(["a", "b", "c"], 1.5);
// → undefined

at(["a", "b", "c"], -1);
// → undefined
Try It Yourself

How It Works

  1. isInteger rejects floats like 1.5.
  2. index < 0 rejects negatives for this helper.
  3. 1 is a valid index → "b".
  4. Tip. For array lengths, also see _.isLength.

Browser & Runtime Support

_.isInteger is a Lodash Lang helper (since 4.0.0). It runs anywhere Lodash 4.x runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install lodash. Behavior aligns with Number.isInteger.

✓ Stable · Lodash 4.0.0+

_.isInteger()

Available in [email protected] full builds and the lodash/isInteger 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
_.isInteger Lodash 4.0.0+

Bottom line: Safe for production once Lodash is loaded. Prefer import isInteger from "lodash/isInteger". Native Number.isInteger is a fine alternative when Lodash is not needed.

Frequently Asked Questions

_.isInteger(value) returns true if value is an integer primitive number. Based on Number.isInteger — no string coercion.
"3" is a string. Parse with Number("3") first if you need an integer check on form input.
Yes for everyday inputs. Lodash documents that this method is based on Number.isInteger.
MIN_VALUE is a tiny positive float, not a whole number — both Lodash and Number.isInteger reject it.
Yes. 3.0 is the same IEEE value as 3, so _.isInteger(3.0) is true.
Use import isInteger from "lodash/isInteger" or require("lodash/isInteger") for tree-shaking. Full build: import _ from "lodash" then _.isInteger.

Next: _.isLength()

Check whether a value is a valid array-like length.

_.isLength() 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.

11 people found this page helpful