a proxy array would be redundant since "maps" are already like that behind
the scene ... which means anytime you need this "proxy array" all you have
to do is Object.keys(yourObject)

Bak to the original question, I would rather think a "map" is not what you
are looking for and it's not clear the order you want to obtain, e.g.

{b:2, aa:1}

Above case, should be "aa" before "b" or not? Are you sure the object will
have properties with a single char only and never two of them as is as
example "aa" ?

Since you are using property name association, what is the reason to have
ordered keys?
Did you know some Opera gives you back keys in reversed order when you
for/in an obejct?

As summary, it would be nice to understand what you really need and why so
we can provide better solutions/examples.

Best Regards,
    Andrea Giammarchi



On Fri, May 27, 2011 at 4:26 PM, Marc Palau <[email protected]> wrote:

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

-- 
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