First define a comparison function:
function compare(el1, el2, index) { return el1[index] == el2[index] ? 0 : (el1[index] < el2[index] ? -1 : 1); }
Then, to sort the array in the first column, use this:
array.sort(function(el1,el2){ return compare(el1, el2, "Functional Category") });
Or, to sort the first column AZ and the second column ZA if the first column is:
array.sort(function(el1,el2){ var compared = compare(el1, el2, "Functional Category") return compared == 0 ? -compare(el1, el2, "Brand Name") : compared; });
Bart
source share