1function sortByKey(array, key) {
2 return array.sort((a, b) => {
3 let x = a[key];
4 let y = b[key];
5
6 return ((x < y) ? -1 : ((x > y) ? 1 : 0));
7 });
8}
1function sortObjectByKeys(o) {
2 return Object.keys(o).sort().reduce((r, k) => (r[k] = o[k], r), {});
3}
4var unsorted = {"c":"crane","b":"boy","a":"ant"};
5var sorted=sortObjectByKeys(unsorted); //{a: "ant", b: "boy", c: "crane"}
1let orders = [
2 {
3 order: 'order 1', date: '2020/04/01_11:09:05'
4 },
5 {
6 order: 'order 2', date: '2020/04/01_10:29:35'
7 },
8 {
9 order: 'order 3', date: '2020/04/01_10:28:44'
10 }
11];
12
13
14console.log(orders);
15
16orders.sort(function(a, b){
17 let dateA = a.date.toLowerCase();
18 let dateB = b.date.toLowerCase();
19 if (dateA < dateB)
20 {
21 return -1;
22 }
23 else if (dateA > dateB)
24 {
25 return 1;
26 }
27 return 0;
28});
29
30console.log(orders);
1list.sort((a, b) => (a.color > b.color) ? 1 : (a.color === b.color) ? ((a.size > b.size) ? 1 : -1) : -1 )
2