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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:32:58+00:00 2026-06-08T21:32:58+00:00

To the best of my understanding, the code var a = new Array(a,b,c); var

  • 0

To the best of my understanding, the code

var a = new Array("a","b","c");
var out = "";
for(i in a)
  out += i+":"+a[i]+"\n";

should set out to

0:a
1:b
2:c

right?

Well, I have the following code snippet in a project of mine:

for(i in player.neededItems)
{
  debug(i+":");
  if(!player.hasItem(player.neededItems[i].type))
    itemsRemaining.push(player.neededItems[i]);
  debug(i+"<br />");
}
  • debug(x) is simply a function that appends x to the contents of a div with id “debug”.
  • player.neededItems is an array of objects.
  • itemsRemaining is a previously empty array.
  • player.hasItem returns wether or not the player has an item.

Ok. So here’s where it get’s weird. In the for loop, ‘i’ is only used as an index to an array. It is not modified in any way. However, the output in “debug” is as follows:

0:3
1:3
2:3
3:3

Why is ‘i’ changing?! player.neededItems does not get modified in any of the functions or anything. I have no idea what is going on. But, when I switch

for(i in player.neededItems)

for

for(i = 0; i < player.neededItems.length; i++)

everything works.

So am I missing something regarding the functionality of ‘for(i in a)’ syntax? Or have I stumbled upon a bug in the javascript parser in webKit? Or (more likely,) am I going mad?

  • 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-08T21:32:59+00:00Added an answer on June 8, 2026 at 9:32 pm
    for(var i in player.neededItems)
    {
      debug(i+":");
      if(!player.hasItem(player.neededItems[i].type))
        itemsRemaining.push(player.neededItems[i]);
      debug(i+"<br />");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following code @using (Html.BeginForm()) { @Html.DropDownListFor(m => m.IDs, new SelectList(Model. IDs), Model.SelectedID)
Best to describe this in code... I have this public class A<T> { public
I have the following piece of code which uses the ALAssets library to store
I have been converting some code from C++ to C#. My lack of understanding
When fixing defects in new code what are the best strategies to use? cause
I'm trying to understanding backbone code. I read this http://addyosmani.com/blog/building-spas-jquerys-best-friends/ then I plan to
Currently i have the following code: This is within my HTML document. <script language=JavaScript
What are the best resources for understanding what's possible (or not possible) to achieve
My understanding of regex and working with strings in php is poor at best
Best explained with code I think, this is just a simple example: public class

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.