'Angular 6 sort JSON array based on inside array key

I've order number inside of the array object. How can I sort data object with order?

data =[
{
name:''
list:{
order :2
},

{
name:''
list:{
order :1
}
]


Solution 1:[1]

Array.sort with a custom comparer function

const data = [
  { name: '', list: { order: 2 },
  { name: '', list: { order: 1 }
];

const ascending = data.sort((a,b) => a.list.order - b.list.order);
const descending = data.sort((a,b) => b.list.order - a.list.order);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Stavm