var availableTags = [
{value:"fruit",desc:"fruit",groupId:2,userId:4},
{value:"aGan",desc:"normal user",groupId:4,userId:5},
{value:"father's home ",desc:"normal user",groupId:2,userId:4}
].sort(function(a, b) { return a.groupId > b.groupId; });
This sorts by groupId
field, but how do I to sort by groupId
and value
?
Sorting a multidimensional array by element containing date. Use the usort() function to sort the array. The usort() function is PHP builtin function that sorts a given array using user-defined comparison function. This function assigns new integral keys starting from zero to array elements.
Use sorted() with a lambda function to sort a multidimensional list by column. Call sorted(iterable, key=None) with key set to a lambda function of syntax lambda x: x[i] to sort a multidimensional list iterable by the i th element in each inner list x .
A multidimensional array in MATLAB® is an array with more than two dimensions. In a matrix, the two dimensions are represented by rows and columns. Each element is defined by two subscripts, the row index and the column index.
A multi-dimensional array can be termed as an array of arrays that stores homogeneous data in tabular form. Data in multidimensional arrays are stored in row-major order. The general form of declaring N-dimensional arrays is: data_type array_name[size1][size2]....[sizeN];
Change the return statement to
return a.groupId > b.groupId || (a.groupId == b.groupId && a.value > b.value);
How about
.sort(function (a, b) {
var firstGroupId = a.groupId;
var secondGroupId = b.groupId;
return (firstGroupId === secondGroupId) ? a.value > b.value : firstGroupId > secondGroupId;
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With