0

Possible Duplicate:
Sorting JavaScript Object by property value
javascript sort object of objects

I have an object of objects. Each object have a key:

{
    name: {key: value,
           key1:BBB},
    name2: {key: value,
            key1:AAA},
    name3: {key: value,
            key1:CCC}
}

I will later select a subset of the keys (name2 and name3 for example): after that I want to sort the remaining items based on the value of key1. How should I go about doin this?

Community
  • 1
  • 1
Himmators
  • 14,278
  • 36
  • 132
  • 223
  • 5
    You cannot sort properties of objects, they are unsorted. You can only sort arrays. Sorting an array of objects is already covered here... – Felix Kling Jun 19 '12 at 20:24
  • So what should I do, load the requierd data into an array an then sort it? – Himmators Jun 19 '12 at 20:40
  • 1
    @KristofferNolgren if your object contains only a bunch of objects that are the same structure/schema then you could loop through the main object and move the child objects into an array and sort the array. – pseudosavant Jun 19 '12 at 20:43

0 Answers0