<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/how-do-i-compare-two-objects-in-javascript--ej6jlf-iq" -->

---
title: How do I compare two objects in JavaScript? | daily.dev
description: The equals helper function is used to compare two objects. It can be useful in some situations, but it can have its own pitfalls. The most common of these has...
canonical: https://daily.dev/posts/how-do-i-compare-two-objects-in-javascript--ej6jlf-iq
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: How do I compare two objects in JavaScript? | daily.dev
og:description: The equals helper function is used to compare two objects. It can be useful in some situations, but it can have its own pitfalls. The most common of these has...
og:url: https://daily.dev/posts/how-do-i-compare-two-objects-in-javascript--ej6jlf-iq
og:image: https://api.daily.dev/og/posts/ej6jlf-IQ.png
og:image:alt: How do I compare two objects in JavaScript?
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# How do I compare two objects in JavaScript?

**[30 seconds of code](https://daily.dev/sources/30seconds)** · 2 min read · 15 upvotes · 1 comments

## Summary

The equals helper function is used to compare two objects. It can be useful in some situations, but it can have its own pitfalls. The most common of these has to do with similar, but not equal, values that result in the same serialized string. This is because arrays and objects in JavaScript are compared by reference.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.30secondsofcode.org/articles/s/javascript-object-comparison>

## Community discussion

Top comments from developers on daily.dev.

**@dailydevtips** · 2 upvotes

> Well written and great examples!

---

Tags: [#javascript](https://daily.dev/tags/javascript)

[View this post on daily.dev](https://daily.dev/posts/how-do-i-compare-two-objects-in-javascript--ej6jlf-iq)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"How do I compare two objects in JavaScript?","url":"https://daily.dev/posts/how-do-i-compare-two-objects-in-javascript--ej6jlf-iq","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/how-do-i-compare-two-objects-in-javascript--ej6jlf-iq"},"datePublished":"2021-09-26T18:48:02.005Z","dateModified":"2021-10-07T14:17:10.317Z","description":"The equals helper function is used to compare two objects. It can be useful in some situations, but it can have its own pitfalls. The most common of these has...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/a9acb76c5913fb1463108e31c76cf000","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/a9acb76c5913fb1463108e31c76cf000","isAccessibleForFree":true,"articleSection":"30 seconds of code","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"30 seconds of code","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/197d6538eea141d7a2fb4177234e9d89","url":"https://daily.dev/sources/30seconds"},"commentCount":1,"discussionUrl":"https://daily.dev/posts/how-do-i-compare-two-objects-in-javascript--ej6jlf-iq","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":15},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":1}],"keywords":"javascript","timeRequired":"PT2M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"30 seconds of code","item":"https://daily.dev/sources/30seconds"},{"@type":"ListItem","position":3,"name":"How do I compare two objects in JavaScript?"}]}
{"@context":"https://schema.org","@type":"WebPage","@id":"https://daily.dev/posts/how-do-i-compare-two-objects-in-javascript--ej6jlf-iq","comment":[{"@type":"Comment","text":"Well written and great examples!","datePublished":"2021-09-27T06:02:40.274Z","url":"https://daily.dev/posts/ej6jlf-IQ#c-pqFmLISQt","author":{"@type":"Person","name":"Chris Bongers","url":"https://daily.dev/dailydevtips","image":"https://media.daily.dev/image/upload/s--9gxFz1e7--/f_auto/v1705902590/avatars/avatar_JUNiIGCV-?_a=BAMAMiZW0"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":2}}]}
```

