Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Dec 2011
    Thanked 0 Times in 0 Posts

    Sorting Objects (just for my understanding)

    I have an Object, containing an object, containing an object....etc.
    So, it's an Object of objects. Not an Array of objects.
    And now I want to sort this Object of objects.
    Is there a "native" way in JavaScript to sort an object?
    Or do I understand it correctly, that I first have to convert the Object to an Array, and than perform an array.sort ?

    This question is just for my understanding of JavaScript, so I don't go into the wrong direction.
    Tnx in advance for any explanation.

  2. #2
    Administrator chump2877's Avatar
    Join Date
    Dec 2004
    the U.S. of freakin' A.
    Thanked 176 Times in 167 Posts
    Please see the following links:


    Array.sort accepts a callback function that you can use to sort the values in an array...If the values in the array are objects, then you can reference the object properties in your callback function -- and sort by object properties.

    So, if you want to use the built in Array.sort feature, you'll have to convert one or more of your objects into arrays.

    Of course, I don't see why you couldn't write your own sorting function for objects, and perhaps add the function to the Object prototype.
    Regards, R.J.


    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :-)
    [Instructional videos and tutorials are also available on YouTube, Dailymotion, and Vimeo]
    Get free updates about new software version releases, features, and bug fixes!
    ♪♪ …Need Web Hosting For My YouTube-To-Mp3 Conversion Software? Check Here !!… ♪♪


Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts