Lodash _.isEqual() method

Beginner
⏱️ 7 min read
📚 Updated: May 2026
🎯 3 Code examples
🚀 3 Try-it labs
Lodash

What you’ll learn

  • How _.isEqual(value, other) compares nested objects and arrays by content.
  • Why it differs from === for objects with matching structure.
  • How dates and maps behave in deep equality checks.
  • When reference identity still matters for functions and DOM nodes.

Prerequisites

Basic JavaScript object/array references and familiarity with strict equality (===).

  • You know two object literals can look the same but still be different references.
  • Try-it labs use lodash from the CDN.

Overview

Use _.isEqual when comparing cache snapshots, form drafts, API payloads, or test fixtures where nested structure matters more than object identity.

Deep structure

Compares nested values recursively rather than only top-level references.

Broad type support

Handles arrays, dates, maps, sets, typed arrays, and plain objects.

Identity exceptions

Functions and DOM nodes still compare by strict identity.

Syntax

javascript
_.isEqual(value, other)
  • value: first value to compare.
  • other: second value to compare.
  • Returns: true if deeply equivalent; otherwise false.
1

Nested objects with matching content

Different references can still be deeply equal when keys and values match recursively.

javascript
import isEqual from "lodash/isEqual";

var a = { user: { id: 7, roles: ["admin", "editor"] } };
var b = { user: { id: 7, roles: ["admin", "editor"] } };

console.log(
  "deepMatch: " + isEqual(a, b) + "\n" +     // true
  "strictEq: " + (a === b)                    // false
);
Try it Yourself
2

Arrays and Date values

Order matters in arrays; dates compare by their underlying time value.

javascript
import isEqual from "lodash/isEqual";

console.log(
  "arrayOrder: " + isEqual([1, 2], [2, 1]) + "\n" +                  // false
  "sameDateVal: " + isEqual(new Date("2024-06-01"), new Date("2024-06-01")) // true
);
Try it Yourself
3

Map contents and function identity

Maps with equivalent entries can match deeply, while different function references do not.

javascript
import isEqual from "lodash/isEqual";

var mapA = new Map([["k", { n: 1 }]]);
var mapB = new Map([["k", { n: 1 }]]);
var fnA = function () { return 1; };
var fnB = function () { return 1; };

console.log(
  "mapMatch: " + isEqual(mapA, mapB) + "\n" +   // true
  "fnIdentity: " + isEqual(fnA, fnB)            // false
);
Try it Yourself

📋 _.isEqual vs related checks

APIMatches
_.isEqual(a, b)Deep structural equality across many value types.
a === bStrict identity (or primitive equality) only.
JSON.stringify(a) === JSON.stringify(b)String-based approximation, sensitive to key order and unsupported values.
_.isMatch(a, b)Partial deep match, not full equivalence.

Pitfalls to avoid

Performance

Deep checks in hot loops

Repeated deep comparisons can be expensive; cache normalized forms or narrow fields first.

Functions

Same body, different reference

Two separately created functions are not equal unless they are the exact same reference.

Requirements

Need custom comparison rules?

Use _.isEqualWith when domain-specific tolerance (e.g., case-insensitive strings) is required.

❓ FAQ

Strict equality compares references for objects and arrays. _.isEqual walks nested values and compares structure and content.
Yes. Lodash supports deep equality for Map and Set collections in addition to arrays and plain objects.
No. Functions are compared by identity (same reference), not by their textual body.
Be careful. Deep comparison is more expensive than shallow checks, so memoization keys and frequent renders may need narrower comparisons.

Summary

  • Purpose: compare complex values deeply when reference equality is too strict.
  • Remember: functions and DOM nodes compare by identity, not by structure.
  • Next: explore more on Lodash _.isEqualWith().
Did you know?

_.isEqual performs deep value comparison (arrays, objects, maps, sets, dates, typed arrays, and more), but functions and DOM nodes are compared by strict identity (===).

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.

6 people found this page helpful