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
  • 23,141
  • 55
  • 131
  • 179

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
  • 630,263
  • 148
  • 957
  • 1,375