What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » [?] Sort array by keys...

[?] Sort array by keys...
Author: Message:
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
31 / Male / Flag
Joined: Apr 2004
RE: [?] Sort array by keys...
JScript arrays can't have strings as keys, you're just extending the Object instance with W, X, Y and Z properties. They're not actually array elements, you can easily see this when you check MyArr.length (it'll still be 0).

As for sorting object properties, I see two possible solutions. You could create a new object and define the properties in the sorted order, as Eljay proposed. Or you could keep the same object and delete the properties with delete MyObj[K] and then re-add the properties. This preserves prototypes as you're working on the same object you started with.

However, like Eljay I also wonder why you'd need to do this anyway. Objects are great to retrieve a value by its key name and store values with their keys. The order of those values is not important for these tasks since objects don't and shouldn't behave like ordered lists. If you really need hashes with sorting behavior, you might be better off creating something like a custom sorted hash table class with getter/setter and enumerator methods.
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
07-30-2010 07:47 PM
Profile E-Mail PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
[?] Sort array by keys... - by whiz on 07-23-2010 at 06:30 PM
RE: [?] Sort array by keys... - by roflmao456 on 07-23-2010 at 07:01 PM
RE: [?] Sort array by keys... - by Adeptus on 07-23-2010 at 07:12 PM
RE: [?] Sort array by keys... - by Eljay on 07-23-2010 at 07:13 PM
RE: [?] Sort array by keys... - by whiz on 07-23-2010 at 07:18 PM
RE: [?] Sort array by keys... - by Matti on 07-30-2010 at 07:47 PM
RE: [?] Sort array by keys... - by whiz on 07-31-2010 at 09:46 AM
RE: [?] Sort array by keys... - by Matti on 07-31-2010 at 12:56 PM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On