Al 27/05/11 16:18, En/na Nick Morgan ha escrit:
2011/5/27 Björn Söderqvist<[email protected]>:
I have an object whose properties are not alphabetically sorted, like so:
{a:1, c:3, b:2}
I would now like to have a function which can return a similar object,
only with the properties sorted alphabetically:
{a:1, b:2,c:3}

If it's essential that you have an ordered representation, use an array:

[['a', 1], ['b', 2], ['c', 3]];

Or better, if you need to maintain the object structure, use a proxy array to order:

var order = ['a','b','c','d'];
var object = { d : 4 , b : 2 , a : 1 , c : 3};
var el;
for(var i=0,t=order.length;i<t;i++){
    el = order[i];

    console.log(object[el]);
};

cheers
Marc

--
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to