can anyone please tell me how to sort the below array of values using javascript.
var cols = new Array();
cols[0] = 13,000,000;
cols[1] = -20.45;
cols[2] = 0.0;
cols[3] = 10,000;
cols[4] = 750.00
cols[5] = 41.00;
I have tried the below two methods for sorting
cols.sort();
cols.sort(function (a,b){return a-b;});
the results are some thing like below.
cols[0] = -20.45;
cols[1] = 0.0;
cols[2] = 10,000;
cols[3] = 13,000,000;
cols[4] = 41.00;
cols[5] = 750.00
`
cols[0] = 13,000,000;That's not going to give you the number you want. Are they actually strings?0and0.,. I tested withvarwhich changes the meaning of the,a bit. EDIT: ...actually I tested in the console withoutvar. Too tired right now.