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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:45:07+00:00 2026-06-10T02:45:07+00:00

I noticed that when enumerating the properties of an object, that it seems like

  • 0

I noticed that when enumerating the properties of an object, that it seems like a snapshot of the current properties is taken at start of the loop, and then the snapshot is iterated. I feel this way because the following doesn’t create an endless loop:

var obj = {a:0,b:0}, i=0;
for (var k in obj) {
    obj[i++] = 0;
}
alert(i) // 2

demo http://jsfiddle.net/kqzLG/

The above code demonstrates that I’m adding new properties, but the new properties won’t get enumerated.

However, the delete operator seems to defy my snapshot theory. Here’s the same code, but deleting a property before it gets enumerated.

var obj = {a:0,b:0}, i=0;
for (var k in obj) {
    i++;
    delete obj.b;
}
alert(i) // 1

demo http://jsfiddle.net/Gs2vh/

The above code demonstrates that the loop body only executed one time. It would have executed twice if the snapshot theory were true.

What’s going on here? Does javascript have some type of hidden iterator that it uses, and the delete operator is somehow aware of it?

— I realize that I’m assuming something about iteration order- specifically that iteration occurs based off of property insertion time. I believe all browsers use such an implementation.

  • 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-10T02:45:08+00:00Added an answer on June 10, 2026 at 2:45 am

    Interesting question. The answer lies in the specification (emphasis mine):

    The mechanics and order of enumerating the properties (step 6.a in the first algorithm, step 7.a in the second) is not specified. Properties of the object being enumerated may be deleted during enumeration. If a property that has not yet been visited during enumeration is deleted, then it will not be visited. If new properties are added to the object being enumerated during enumeration, the newly added properties are not guaranteed to be visited in the active enumeration. A property name must not be visited more than once in any enumeration.

    So it is explicitly specified that a deleted property must not be traversed anymore. However, the behaviour for adding a new property is implementation dependent, most likely because it is not defined how properties should be stored internally.

    For example in Chrome, it seems that numeric properties are stored before alphabetical ones:

    > Object.keys({a:0, 0:1});
      ["0", "a"]
    

    However, even if you add alphabetical keys:

    var obj = {a:0,b:0};
    for (var k in obj) {
        obj['c'] = 0;
        console.log(k);
    }
    

    c does not seem to be traversed, the output is a b.

    Firefox shows the same behaviour, although keys are stored in insertion order:

    > Object.keys({a:0, 0:1});
      ["a", "0"]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I noticed that Clojure (1.4) seems to be happy to consider vectors equal to
I noticed that when I do something like this (with jQuery, but I don't
I noticed that most (all?) .winmd files have a version of 255.255.255.255 like: Windows,
I noticed that itertools does not (it seems to me) have a function capable
I noticed something that seems odd in the following code: MatchCollection mc = Regex.Matches(myString,
I noticed that line-height seems to affect blocks. Its strange to me, that i
I noticed that you can call Queue.Synchronize to get a thread-safe queue object, but
I noticed that if i do a git rebase -i HEAD~10 and then don't
I noticed that if I try to compile lines of Coffeescript like this: $note.find('a.close').bind
I noticed that some enumerations have None as a enumeration member. For example what

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.