ts order array by value code example
Example 1: javascript sort object by key
function sortObjectByKeys(o) {
return Object.keys(o).sort().reduce((r, k) => (r[k] = o[k], r), {});
}
var unsorted = {"c":"crane","b":"boy","a":"ant"};
var sorted=sortObjectByKeys(unsorted); //{a: "ant", b: "boy", c: "crane"}
Example 2: how to sort numbers in typescript
var numericArray: number[] = [2, 3, 4, 1, 5, 8, 11];
var sortedArray: number[] = numericArray.sort((n1,n2) => n1 - n2);