Lodash _.isObject() method
What you’ll learn
- How
_.isObject(value)filters nullish values then inspectstypeof. - Why arrays, plain objects, and functions all qualify.
- How this differs from
_.isObjectLikeand_.isPlainObject. - When to narrow further before treating input as a data record.
Prerequisites
You understand JavaScript typeof quirks (including typeof null === "object") at a basic level.
- You know arrays are objects in JavaScript.
- Try-it labs load lodash from the CDN.
Overview
Reach for _.isObject when guarding generic merges, serializers, or middleware that should reject primitives yet accept structured builtins—from POJOs and arrays to callables.
Broad structural
Arrays, dates, regex literals, and plain maps-of-keys qualify.
Functions allowed
Treats callable references as object-category values.
Nullish out
null and undefined fail before typeof tricks matter.
Syntax
_.isObject(value) - value: any value to test.
- Returns:
truewhen value is non-nullish andtypeofis"object"or"function".
Plain objects and arrays
Lodash documents both collections as objects.
import isObject from "lodash/isObject";
console.log(
"pojo: " + isObject({}) + "\n" + // true
"array: " + isObject([1, 2, 3]) // true
); Nullish and primitives
null is ruled out explicitly; strings and numbers stay primitives.
import isObject from "lodash/isObject";
console.log(
"nullVal: " + isObject(null) + "\n" + // false (lodash docs)
"undef: " + isObject(undefined) + "\n" + // false
"num: " + isObject(42) // false
); Functions: _.isObject vs _.isObjectLike
Functions count as objects for lodash; _.isObjectLike excludes them.
import isObject from "lodash/isObject";
import isObjectLike from "lodash/isObjectLike";
console.log(
"fnIsObject: " + isObject(function () {}) + "\n" + // true (lodash docs use _.noop)
"fnObjectLike: " + isObjectLike(function () {}) // false
); 📋 _.isObject vs related helpers
| API | Behavior |
|---|---|
_.isObject(x) | Non-nullish object or function typeof. |
_.isObjectLike(x) | Non-nullish typeof === "object" only—functions excluded. |
_.isPlainObject(x) | Simple dictionaries—arrays, dates, and classes fail. |
x instanceof Object | Often similar but prototype quirks exist for primitives. |
Pitfalls to avoid
“JSON-like” assumptions
_.isObject is broad—validate shapes separately before treating payloads as records.
Host objects
Elements and exotic builtins usually still report typeof object—pair with feature checks.
Micro-optimization
Inline guards suffice in hot paths; lodash shines when chaining readability matters.
❓ FAQ
Summary
- Purpose: coarse filter for non-null structural/callable values.
- Remember: tighten with
_.isPlainObject,Array.isArray, or schema validators when shape matters. - Next: explore more on Lodash _.isObjectLike().
_.isObject is defined as value != null && (typeof value === "object" || typeof value === "function")—so typeof function counts, unlike _.isObjectLike, which only allows typeof "object".
6 people found this page helpful
