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 626401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:24:55+00:00 2026-05-13T19:24:55+00:00

Both methods appear to produce the same results , but I’ve been hard-pressed to

  • 0

Both methods appear to produce the same results, but I’ve been hard-pressed to actually convince people that the second method works, since it’s apparently not commonly known.

// Create some data
var foo = { 'vals':[ {'id':'foo'}, {'id':'bar'} ] }​​​​​​​​​​​​​​​​​;

// Common Method    
$.each(foo.vals, function(i,o){
    alert(this.id);
});

// Alternative (lesser-known?) Method
$(foo.vals).each(function(i,o){
   alert(this.id); 
});

Upon checking the source, these two appear to be one-in-the-same. The second method follows:

each: function( callback, args ) {
  return jQuery.each( this, callback, args );
}

This method demonstrably calls the more commonly-known method, meaning it’s just as legitimate. Is this understanding correct, or am I missing something here?

I have typically trusted this method since it didn’t cause me to deviate from standard practices with regards to selectors. Let’s face it, we’re trained to do:

$("p").each();

So it seems only natural to do:

$(obj).each();

Am I mistaken?

  • 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-13T19:24:55+00:00Added an answer on May 13, 2026 at 7:24 pm

    The difference between the two is actually exponential depending on how you are using it.

    The first $.each constitutes a single function call to start the iterator.

    The second $(foo.vals).each makes three function calls to start the iterator. The first is to the $() which produces a new jQuery wrapper set (Not sure how many other function calls are made during this process). Then the call to $().each. And finally it makes the internal call to jQuery.each to start the iterator.

    In your example, the difference would be negligible to say the least. However, in a nested use scenario, you might find performance becoming an issue.

    Finally, Cody Lindley in jQuery Enlightenment does not recommend using $.each for iterations greater than 1000 because of the function calls involved. Use a normal for( var i = 0... loop.

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

Sidebar

Related Questions

Why do this Ruby object both a to_s and inspect methods that appear to
Both methods MyBehavior::CreateSerializer() are not called of some reason, but ReplaceBehavior() method is working.
ActiveRecord's has_many and belongs_to methods both take a :foreign_key option. If I need to
I have parsed XML using both of the following two methods... Parsing the XmlDocument
I have two methods, one called straight after another, which both throw the exact
I'd like to define a method that is available in both my views and
I have 2 classes within same package. Both classes have main method in them.
In .NET, both array and list have Enumerable as ancestor, so a method that
I am working on a project that is both memory and computationally intensive. A
I've got a simple grammar. Actually, the grammar I'm using is more complex, but

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.