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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:55:30+00:00 2026-05-27T14:55:30+00:00

What is the difference if I use one of the following to iterate javascript

  • 0

What is the difference if I use one of the following to iterate javascript arrays:

for (var i = 0 ; i <abc.length :i++)  

or

for (var i in abc.lengh)

Thank you.

  • 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-27T14:55:30+00:00Added an answer on May 27, 2026 at 2:55 pm

    For iterating the elements of an array, you should use this form:

    var x = [1,2,3,4];
    
    for (var i = 0, len = x.length; i < len; i++) {
        // code here to access x[i]
    }
    

    For iterating the properties of an object, you should use this:

    var house = {size: 3200, bedrooms: 5, garage: 2, color: "white", city: "San Francisco"};
    
    for (var key in house) {
        // access each property here as house[key]
    }
    

    Though you can sometimes get away with using the second syntax on an array, you are asking for trouble because it will include custom properties that have been added to the array that are not array elements themselves and that can really confuse the code and lead to subtle or not-so-subtle bugs.

    The addition of the len variable in the first syntax is a speed optimization because fetching the length one into a local variable can be significantly faster than accessing the length property on every iteration of the loop. It is not required to do it this way. It can be done as this also:

    for (var i = 0; i < x.length; i++)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use the following to calculate the difference between two dates in JavaScript: var
What's the difference between the two? Why would you use one over the other?
What is the difference between HttpContext.Current.Request.IsAuthenticated and HttpContext.Current.User.Identity.IsAuthenticated? Which one would you use in
Does any one know the difference, if any, of the following statements? _context.AddObject(user); _context.Users.AddObject(user);
What is the difference b/w the following two codes. What is the use of
Does it make much difference if I use in either of the following in
Is there a difference between the following two? msgbox() messagebox.show() Some tutorials use msgbox(),
What is difference between following code? Code 1: var f = function() { //
What are the differences between htmlspecialchars() and htmlentities() . When should I use one
What are the differences between these two, and which one should I use? string

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.