Skip to content

Instantly share code, notes, and snippets.

@jeremyckahn
Created December 10, 2010 03:53
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 jeremyckahn/735742 to your computer and use it in GitHub Desktop.
Save jeremyckahn/735742 to your computer and use it in GitHub Desktop.
Forcing property orders for browsers
// This code shows how to order the properties of an object numerically.
var a = {}, _a = {}, arr = [], i, p;
a[100] = '100';
a[5] = '5';
a[75] = '75';
for (i in a){
arr.push(parseInt(i, 10));
}
arr.sort(function(a, b){
return a - b;
});
for (i = 0; i < arr.length; i++){
_a[arr[i]] = a[arr[i]];
}
a = _a;
for (p in a){
console.log(p);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment