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

  • SEARCH
  • Home
  • 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 1055271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:32:13+00:00 2026-05-16T17:32:13+00:00

I found this method: Array.prototype.compare = function(arr) { if (this.length != arr.length) return false;

  • 0

I found this method:

Array.prototype.compare = function(arr) {
    if (this.length != arr.length) return false;
    for (var i = 0; i < arr.length; i++) {
        if (this[i].compare) {
            if (!this[i].compare(arr[i])) return false;
        }
        if (this[i] !== arr[i]) return false;
    }
    return true;
}


var a = ['aa',[1,2,3]]
var b = ['aa',[1,2,3]]
alert(a.compare (b))

.
But, when I make a deep compare, it returns false.

So what method do you use to compare two arrays, using jquery?

Thanks

  • 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-16T17:32:13+00:00Added an answer on May 16, 2026 at 5:32 pm

    There’s no jQuery solution for this – jQuery is mainly used for DOM manipulation, ajax and some simple animations. It does come with a small collection of utilities, but as far as I know none of them have this function.

    I did, however, find the bug in your code.

    Array.prototype.compare = function(arr) {
        if (this.length != arr.length) return false;
        for (var i = 0; i < arr.length; i++) {
            if (this[i].compare) {
                if (!this[i].compare(arr[i])) return false;
            } else { // <-- Here!
                if (this[i] !== arr[i]) return false;
            }
        }
        return true;
    }
    

    You need to use if – else here, instead of running both the .compare function again and comparing them with the equality operator.

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

Sidebar

Related Questions

I found out this morning that proc.new works in a class initialize method, but
I found this wonderful clone function for javascript ( http://my.opera.com/GreyWyvern/blog/show.dml/1725165 ), but it breaks
I'm trying to make File Downloads with WGET method of nodejs. I found this:
found this little code snippet that seems to do what i want, but im
Found this Multimap containing pairs? , but it is not much help How would
Found this: Sub SurroundWithAppendTag() DTE.ActiveDocument.Selection.Text = .Append( + DTE.ActiveDocument.Selection.Text + ) End Sub But
Found this post that helped me out: Split a string to form multidimensional array
I know that I can create an associative array like this: var MyAssocArray =
I found this method on the internet: //the call to the method: cout <<
Javascript (ECMAscript) supports the Array.prototype.forEach method since version 1.6 (ECMAscript edition 3, 2005). So

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.