0

I've a big problem. I want to sort an array like this:

 '0' ...
        '0' ...
            'id' => "XXXXX"
            'from' ...
                'name' => "XXXX"
                'id' => "XXXXXXXX"
            'story' => "XXXXXXXXXX"
        '1' ...
            'id' => "XXXXX"
            'from' ...
                'name' => "XXXX"
                'id' => "XXXXXXXX"
            'story' => "XXXXXXXXXX"
        '2' ...
            'id' => "XXXXX"
            'from' ...
                'name' => "XXXX"
                'id' => "XXXXXXXX"
            'story' => "XXXXXXXXXX"

I'd like to sort array by key FROM-NAME. Can you help me?

Sir Crispalot
  • 4,792
  • 1
  • 39
  • 64
  • 1
    Just a point on terminology: you are not sorting an associative array, you are sorting an array of objects. Associative arrays (objects in JS) have no order so they can't be sorted. – Dennis Jul 21 '12 at 12:55

1 Answers1

3

Try this:

yourarray.sort(function(a,b){
    return a.from.name<b.from.name ? -1 : 1;
});
Dennis
  • 32,200
  • 11
  • 64
  • 79
Engineer
  • 47,849
  • 12
  • 88
  • 91