0

Possible Duplicate:
How to sort an array of javascript objects?

i have a array of objects:

var arr = []
arr[0] = new Object()
...
arr[n] = new Object()

I want to get sorted array by arr[i].getSortOrder() for example, where arr[i].getSortOrder() return integer value. How to do it ?

Community
  • 1
  • 1
Bdfy
  • 21,109
  • 53
  • 126
  • 178

1 Answers1

2

Just for the record:

arr.sort(function(a, b){return a.getSortOrder() - b.getSortOrder();});

For details see Sorting an array of JavaScript objects and the MDN docs for the sort() method.

Community
  • 1
  • 1
Bergi
  • 572,313
  • 128
  • 898
  • 1,281