jquery-related-selects icon indicating copy to clipboard operation
jquery-related-selects copied to clipboard

Sort order of elements not maintained with JSON in Google Chrome

Open kiddailey opened this issue 14 years ago • 1 comments

Note that the $.each() function under Chrome appears to not respect the order of the elements as defined in the JSON object returned by the server. When the $.each() is used to add each select item to the dropdown on the successful AJAX call, they become arranged in order of the value for each element.

For example, if I return the following from the web service:

{"2":"First Item","1":"Second Item","3":"Third Item"}

In Chrome, they will appear in the dropdown in the order:

  • Second Item
  • First Item
  • Third Item

In Firefox the order is properly maintained. Not sure about other browsers.

kiddailey avatar Feb 13 '11 02:02 kiddailey

I can confirm this using:

  • Firefox 7 the order is just like in the JSON object
  • Chrome 14 the order is sorted by the key

serbanghita avatar Oct 06 '11 07:10 serbanghita