Sorting Objects in an Array via one of their property.

Hello everyone,

I have an Array which holds Items (extends Object Class). These Items have a property called itemName. Is it possible to sort the array by that object’s property?

I’ve tried both the sort() & sortOn() methods without succkess:

i.e.

var db:Array = [item1, item2, item3,item4]; // item1.itemName=‘d’, item2.itemName=‘c’, …

db.itemName.sort(); // clearly that wouldn’t work.
&
db.sortOn(itemName); // I’m assuming the Sort on Alpha is the default.

Any help is appreciated.

Thanks!

Does db.sortOn("itemName") work?

2 Likes

Yes! tyvm, i can’t believe i missed that! (>_<)

2 Likes