Skip to main content

Bug Tracker

Side navigation

#11034 closed bug (cantfix)

Opened December 15, 2011 03:51PM UTC

Closed December 15, 2011 04:22PM UTC

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

Reported by: loewel@mobiletrend.de Owned by: loewel@mobiletrend.de
Priority: low Milestone: None
Component: core Version: 1.7.1
Keywords: Cc:
Blocked by: Blocking:
Description

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>
<script>	
var container = $('#container');
var data = {
	"3" : {"nr":1},
	"2" : {"nr":2},
	"1" : {"nr":3}
	};	
$.each(data, function(k,e){
	container.append('<span>'+e.nr+'</span>,');
	});
</script>

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.

Attachments (0)
Change History (2)

Changed December 15, 2011 04:02PM UTC by timmywil comment:1

component: unfiledcore
owner: → loewel@mobiletrend.de
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.

Changed December 15, 2011 04:22PM UTC by rwaldron comment:2

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.

http://es5.github.com/#x12.6.4

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