I know that this question has been asked many many times in this community but I hardly see the monitor of my laptop as I'm working for a long time. some help plz.
I want to sort this array of object to get the highest and the lowest value of all the given values that are being inserted to the array automatically.
var catesArrayHolder = new Array();
for(var chartGetter=1; chartGetter <= num; chartGetter++){
var catesArray = new Array();
for(var chartGetterArray=1; chartGetterArray <= series; chartGetterArray++){
idOfInput = "cate"+chartGetter+"_series"+chartGetterArray;
values = $("#"+idOfInput).val();
if(values == ""){
values = 0;
}
catesArray.push(values);
}
catesArrayHolder.push(catesArray);
}
this function does NOT work with me... it works with the one-dimensional arrays
catesArrayHolder.sort(function(a,b){return a-b});
I appreciate your help.
a - b
is only really sensible for numbers. You'll have to define an appropriate ordering function for your objects. In this case, that is actually (anda
andb
represent) an array of values. If order of values doesn't matter, sort the array of values first (cratesArray
) before they are put intocratesArrayHolder
, to make the ordering over the arrays of values simpler. – user166390 Feb 28 '13 at 3:32