Bug Tracker

Opened 11 years ago

Closed 11 years ago

#11034 closed bug (cantfix)

Reverse behavior of $.each() for objects in Chrome, Opera

Reported by: [email protected] Owned by: [email protected]
Priority: low Milestone: None
Component: core Version: 1.7.1
Keywords: Cc:
Blocked by: Blocking:


Hi, don't know, if its a bug of jQuery or of the browsers itself, but it seams that $.each() runs in reversed order on objects using Chrome or Opera (Firefox, Safari & IE8 seems to do it right). Here my shortend example:

<div id="container"></div>
var container = $('#container');
var data = {
	"3" : {"nr":1},
	"2" : {"nr":2},
	"1" : {"nr":3}
$.each(data, function(k,e){

Chrome & Opera displays: 3,2,1, The others: 1,2,3,

Using it with ajax and json will bring some strange behavior here and there. If an simple array with inner objects is used (like [{"nr":1},{"nr":2},{"nr":3}]) all will be right.

Change History (2)

comment:1 Changed 11 years ago by timmywil

Component: unfiledcore
Owner: set to [email protected]
Priority: undecidedlow
Status: newpending

Thanks for taking the time to contribute to the jQuery project! Please provide a complete reduced test case on jsFiddle to help us assess your ticket.

Additionally, be sure to test against the jQuery Edge version to ensure the issue still exists. To get you started, use this boilerplate: http://jsfiddle.net/FrKyN/. Open the link and click to "Fork" (in the top menu) to get started.

comment:2 Changed 11 years ago by Rick Waldron

Resolution: cantfix
Status: pendingclosed

JavaScripts objects specify no particular order and implementations are not bound to preserve the order of object property fields. If you need numerically ordered behaviour, use an array.


The mechanics and order of enumerating the properties (step 6.a in the first algorithm, step 7.a in the second) is not specified.

Note: See TracTickets for help on using tickets.