Bug Tracker

Opened 14 years ago

Closed 14 years ago

#4337 closed bug (invalid)

Interation over array in google chrome iterate ascending by the array keys

Reported by: altar Owned by:
Priority: major Milestone: 1.4
Component: core Version: 1.3.2
Keywords: Cc:
Blocked by: Blocking:


If I have an array like var arr = {2: 'foo', 1: 'bar'}

and in jquery use:

$.each(arr, function(i, item) {



in firefox console output contains keys 2,1 in google chrome console output contains keys 1,2

I tested it on very huge arrays and it seems, that google chrome interate over that by it's keys, thats wrong.

Change History (2)

comment:1 Changed 14 years ago by JDay

This looks like a Chrome bug: http://code.google.com/p/chromium/issues/detail?id=883

jQuery could compensate by sorting the keys, but the performance hit would surely outweigh any benefits.

comment:2 Changed 14 years ago by dmethvin

Resolution: invalid
Status: newclosed

Technically a Javascript implementation doesn't need to guarantee the order (ECMA-262 3rd edition, section 4.2). Since browsers generally return the keys in order of definition there is code out there that unwisely depends on it. I suspect Chrome will "fix" their implementation to compensate.

jQuery can't sort the keys in the general case because that would break code that assumed the keys would be returned in definition order.

Note: See TracTickets for help on using tickets.