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:
Eljay
Elite Member
*****

Avatar
:O

Posts: 2949
Reputation: 77
– / Male / –
Joined: May 2004
RE: [?] Sort array by keys...
Objects can't be sorted by any built-in function that I know of. If you just need to access them in order you can create a separate array containing just the keys and sort that.

JScript code:
var MyObj = {}; // Define empty object
MyObj["X"] = 'bbbb';
MyObj["Z"] = 'dddd';
MyObj["W"] = 'aaaa';
MyObj["Y"] = 'cccc';
 
// Put keys in array and sort
var keyArray = [];
for(key in MyObj) keyArray.push(key);
keyArray.sort();
 
// Loop through object using keyArray order
for(var i=0; i<keyArray.length; ++i)
    Debug.Trace(MyObj[keyArray[i]]);


It really depends what you want to do with the values and why they need to be in a particular order.
07-23-2010 07:13 PM
Profile PM 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