> Hi,
Hi

> How can I sort an Object?
>
> For example I have the following object:
> {banana:"yellow", apple:"green", lemon:"yellow", cherry:"red"}
>
> and I need to sort it so that it looks like this:
> {apple:"green", banana:"yellow", cherry:"red", lemon:"yellow"}
>

<code>
var notSorted:Object= {banana:"yellow", apple:"green", lemon:"yellow",
cherry:"red"};
var properties:Array = new Array();
for ( var abc:Object in notSorted )
{
  properties.push( abc );
}
properties.sort();

// Now the property names are sorted
for each ( var prop:Object in properties )
{
  trace( prop ); // Do something Or u can do notSorted[ prop ], to
access the value.
}
</code>

Regards,
Edward Yakop

Reply via email to