Noticed an inconsistency across browsers when looping associative arrays with numberic keys.
Chrome sorts it ascending. and other browsers(firefox) keep the order in which its created.
All shows it sorted when doing console.log.
I ended up adding a prefix to keys to fix the issue.
So which browser is doing right as per ECMA spec?
- $(function () {
- var o = {
- "55": "five",
- "44": "four",
- "33": "three",
- "22": "two",
- "11": "one"
- };
- $.each(o, function (i) {
- alert(i);
- });
- for(var i in o) {
- alert(o[i]);
- }
- });