Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6676081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:56:32+00:00 2026-05-26T03:56:32+00:00

The following is done in Firebug: >>> [1, 2] == [1, 2] false >>>

  • 0

The following is done in Firebug:

>>> [1, 2] == [1, 2]
false

>>> ({a : 1}) == ({a : 1})
false

I thought Javscript has some rule that says, if an Object or Array has the same references to the same elements, then they are equal?

But even if I say

>>> foo = {a : 1}
Object { a=1}

>>> [foo] == [foo]
false

>>> ({a: foo}) == ({a: foo})
false

Is there a way to make it so that it can do the element comparison and return true?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T03:56:33+00:00Added an answer on May 26, 2026 at 3:56 am

    { } and [ ] are the same as new Object and new Array

    And new Object != new Object (ditto with Array) because they are new and different objects.

    If you want to know whether the content of two arbitary objects is the “same” for some value of same then a quick (but slow) fix is

    JSON.parse(o) === JSON.parse(o)

    A more elegant solution would be to define an equal function (untested)

    var equal = function _equal(a, b) {
      // if `===` or `==` pass then short-circuit
      if (a === b || a == b) { 
        return true;
      }
      // get own properties and prototypes
      var protoA = Object.getPrototypeOf(a), 
          protoB = Object.getPrototypeOf(b),
          keysA = Object.keys(a), 
          keysB = Object.keys(b);
    
      // if protos not same or number of properties not same then false
      if (keysA.length !== keysB.length || protoA !== protoB) {
        return false;
      }
      // recurse equal check on all values for properties of objects
      return keysA.every(function (key) {
        return _equal(a[key], b[key]);
      });
    };
    

    equals example

    Warning: writing an equality function that “works” on all inputs is hard, some common gotchas are (null == undefined) === true and (NaN === NaN) === false neither of which I gaurd for in my function.

    Nor have I dealt with any cross browser problems, I’ve just assumed ES5 exists.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want something similar to the following pseudocode: myGridView.SelectedIndex = myGridView.DataKeys.IndexOf(mySpecificKey); I've done some
Using jQuery, in Firebug, if the following is done one by one: foo =
I'm trying to get the following thing done: public delegate void SomeMethod(params object[] parameters);
Is there any way to put NSButton object over QTCaptureView? I have done following,
I have done the following in a LoginForm: Private Sub OK_Click(ByVal sender As System.Object,
If possible I would like to get some ideas to get the following done
I've done the following test: private static object threadLocker = new object(); private static
I have done the following code in JavaScript to put focus on the particular
I have done the following form <% form_for @anexo, :url => {:action => create},
Essentially I'm wondering if the following can be done in Ruby. So for example:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.