Javascript ~ sort array


var array = [[1, "grape", 42], [2, "fruit", 9]];
array.sort(function(a, b)
{
if (a[1] == b[1]) { return 0; }
if (a[1] > b[1])
{
return 1;
}
else
{
return -1;
}
});


reference
http://stackoverflow.com/questions/5503900/how-to-sort-an-array-of-objects-with-jquery-or-javascript

沒有留言:

發佈留言