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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:00:27+00:00 2026-06-10T01:00:27+00:00

It is my understanding that the following two uses of each do the same

  • 0

It is my understanding that the following two uses of each do the same thing. Is one preferred over the other? My objective it to create a table with the returned data. Thanks

$.get('getList.php',
function (data)
{
    $.each(data, function(i, value) {console.log(value);})
    $(data).each(function(){console.log(this);});
    for(var i=0; i<data.length; i++) {console.log(data[i]);}
    for (i in data) {console.log(data[i]);}
},'json');
  • 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-06-10T01:00:30+00:00Added an answer on June 10, 2026 at 1:00 am

    Given that data will be a JS object and not a DOM element you should use:

    $.each(data, ...
    

    Because $.each() is intended as a generic iterator over any object or array.

    The $(data).each(... syntax is intended to iterate over DOM elements contained in a jQuery object. If you create a jQuery object containing data and data is not an array I think you’ll find that $(data).each(... will run one iteration that returns the whole object rather than one iteration per property. If data is an array it will iterate over the elements, but it’s not really the intended use.

    Using for (i in data) is fine if data is not an array (if it is an array you should use a standard for loop not a for..in), but since you’re using jQuery anyway you might as well stick with $.each() unless there is a performance concern.

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

Sidebar

Related Questions

It is my understanding that two unequal objects can have the same hashcode. How
It is my understanding that one can handle events through Swing by adding a
I have an algorithm that uses the following OpenSSL calls: HMAC_update() / HMAC_final() //
While debugging a javascript code that uses jQuery I found the following code: [0,
The C++ standard mandates that all conforming implementations support the following two signatures for
I have two tables having 1 to 1 relationship. One table called Person and
I have a structure similar to the following: /root/ /root/data/ /root/data/script.php /root/data/some.json /root/data/feature/one.json /root/data/feature/two.json
I have inherited a project that uses the following pattern for passing parameters from
Why arn't the following two scripts equivalent? (Taken from another question: Understanding Python Decorators
Understanding that I should probably just dig into the source to come up with

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.