-
Notifications
You must be signed in to change notification settings - Fork 656
How to group and sort a JS array
agershun edited this page Dec 28, 2014
·
1 revision
Source: StackOverflow.com
There is an array of objects with two properties: Name and Hours.
For example:
array = [
{name: "ANDY", hours: 40 },
{name: "ANDY", hours: 50 },
{name: "GREG", hours: 40 },
];
For example I would like the result of the sorting to have the Andy with the most hours first, then Andy with slightly less hours, and then Greg because his name comes later alphabetically and so on and so on.
var res = alasql('SELECT * FROM ? ORDER BY Name, Hours DESC',[array]);
Try this example at jsFiddle
© 2014-2024, Andrey Gershun & Mathias Rangel Wulff
Please help improve the documentation by opening a PR on the wiki repo