I generally post the code I have so far, but I have nothing on this one… 🙁
How would I go about re-ordering the following array so that I can base it on the value in the ‘percentage’ key, either low-to-high or high-to-low?
var data = [{
"id": "q1",
"question": "blah blah blah",
"percentage": "32"
}, {
"id": "q2",
"question": "blah blah blah",
"percentage": "23"
}, {
"id": "q3",
"question": "blah blah blah",
"percentage": "11"
}, {
"id": "q4",
"question": "blah blah blah",
"percentage": "3"
}, {
"id": "q5",
"question": "blah blah blah",
"percentage": "6"
}]
A bit of correction, it’s not a multidimensional array, it’s an array of objects, you most likely mixed up the naming from
PHP, for your question, use the optional function argument of sort to define your own sorting order.http://jsfiddle.net/cEfRd/