public
Last active

object enumeration test

  • Download Gist
lineate.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12
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);

// 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"]

// 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"]

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.