Skip to content

Instantly share code, notes, and snippets.

@dvdrtrgn
Created January 2, 2012 18:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dvdrtrgn/1551668 to your computer and use it in GitHub Desktop.
Save dvdrtrgn/1551668 to your computer and use it in GitHub Desktop.
object enumeration test
function lineate(obj){
var arr = [], i;
for (i in obj) arr.push([i,obj[i]].join(':'));
console.log(arr);
}
var obj = { a:1, b:2, c:3, "123":'xyz' };
/* log1 */ lineate(obj);
obj.a = 4;
/* log2 */ lineate(obj);
delete obj.a;
obj.a = 4;
/* log3 */ lineate(obj);
@dvdrtrgn
Copy link
Author

dvdrtrgn commented Jan 2, 2012

// Safari & Firefox
// ["a:1", "b:2", "c:3", "123:xyz"]
// ["a:4", "b:2", "c:3", "123:xyz"]
// ["b:2", "c:3", "123:xyz", "a:4"]

// Chrome (still!) & Opera
// ["123:xyz", "a:1", "b:2", "c:3"]
// ["123:xyz", "a:4", "b:2", "c:3"]
// ["123:xyz", "b:2", "c:3", "a:4"]

@saik0
Copy link

saik0 commented May 23, 2013

// IE 9, 10
// ["123:xyz", "a:4", "b:2", "c:3"]
// ["123:xyz", "a:4", "b:2", "c:3"]
// ["123:xyz", "a:4", "b:2", "c:3"]

@anotheredward
Copy link

//Safari & Firefox
// ["123:xyz", "a:1", "b:2", "c:3"]
// ["123:xyz", "a:4", "b:2", "c:3"]
// ["123:xyz", "b:2", "c:3", "a:4"]

As far as I can see it's now the same across all modern browsers, but sadly not purely insertion order :(.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment