I have an array which contains 3 elements:
Field1
Field2
Field3
I need to sort this array by Field2. I have been trolling through the internet and all I seem to see is arrays with only one element being sort.
I have an array which contains 3 elements:
Field1
Field2
Field3
I need to sort this array by Field2. I have been trolling through the internet and all I seem to see is arrays with only one element being sort.
You can supply a comparison function to the sort
method:
theArray.sort(function(a, b){
if (a.Field2 == b.Field2) return 0;
if (a.Field2 < b.Field2) return -1;
return 1;
});
Sorry, but I don't understand your problem. To sort an need a condition to specify an order.
When you sort this array by Field2 then I guess Field2 would be the first element. And What would come second? And why? Field3 or Field1?