Skip to main content

Bug Tracker

Side navigation

#4337 closed bug (invalid)

Opened March 12, 2009 08:32AM UTC

Closed March 21, 2009 02:31PM UTC

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.

Attachments (0)
Change History (2)

Changed March 20, 2009 05:28AM UTC by JDay comment:1

This looks like a Chrome bug:

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

Changed March 21, 2009 02:31PM UTC by dmethvin comment:2

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.