Summary: | The order of objects in an array are not sequential - Moz, FF, IE, Opera are okay | ||
---|---|---|---|
Product: | [Applications] konqueror | Reporter: | Charles Phoenix <phoenixreads> |
Component: | kjs | Assignee: | Konqueror Developers <konq-bugs> |
Status: | RESOLVED DUPLICATE | ||
Severity: | normal | ||
Priority: | NOR | ||
Version: | unspecified | ||
Target Milestone: | --- | ||
Platform: | unspecified | ||
OS: | Linux | ||
Latest Commit: | Version Fixed In: | ||
Sentry Crash Report: |
Description
Charles Phoenix
2005-04-25 04:58:42 UTC
So, if you do: arr['cherry'] = 1; arr['apple'] = 1; arr['banana'] = 1; for (i in arr) document.write(i + ' '); The output will not necessarily be "cherry apple banana"? If that is the case, unless the ECMA standard makes this contract, I don't see why the order should be kept. Alphabetic might be expected, but, again, unless mandated by the standard, there is no reason to. The internal representation is probably a hashing-table, whose iteration order is not guaranteed. In fact, we can relate to: arr[2] = 1; arr[0] = 1; arr[1] = 1; for (i in arr) document.write(i); The output will probably not be "201". See bug #28474, I think this is a dupe Granted it is not "official" behavior but it is "unofficial" behavior. It comes down to a design choice. Something to add to the learning... do not program based on *any* assumptions. Thank you. And yes you can mark this as dupe. Reopening to mark as duplicate. |