Bug Tracker

Ticket #4337 (closed bug: invalid)

Opened 6 years ago

Last modified 6 years ago

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:
Blocking: Blocked by:

Description

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

and in jquery use:

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

console.log(i);

});

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

comment:1 Changed 6 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 6 years ago by dmethvin

  • Status changed from new to closed
  • Resolution set to invalid

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.