Secret Array.sort() function argument lets you sort an array of objects by a property
-
inline function sortByProperty(arr, prop) { arr.sort(function[prop](a, b) { if (a[prop] < b[prop]) return -1; if (a[prop] > b[prop]) return 1; return 0; }); return arr; } var array = [ {"name": "John", "age": 25}, {"name": "Jane", "age": 22}, {"name": "Joe", "age": 30}, {"name": "Jack", "age": 3}, ]; Console.print(trace(sortByProperty(array, "age")));
-
@aaronventure Ooo that's sneaky