How to sort javascript array with objects?


var people = [
    {Name: "Jack Lee", Age: 21},
    {Name: "Jack Ma", Age:31},
    {Name: "Steve Liu", Age: 12},
    {Name: "Alice  Xu", Age: 42}
];


//Sort by name
people.sort(function(a,b){
   return   (a.Name.toLowerCase() > b.Name.toLowerCase()) ? 1 : -1;
});

//Sort by ES6 arrow function
people.sort((a,b)=>{
   return   (a.Name.toLowerCase() > b.Name.toLowerCase()) ? 1 : -1;
});

Sorted array by name:
>people
 
0: {Name: "Alice  Xu", Age: 42}
1: {Name: "Jack Lee", Age: 21}
2: {Name: "Jack Ma", Age: 31}
3: {Name: "Steve Liu", Age: 12} 


//sort by age
 people.sort(function(a,b){
   return   (a.Age > b.Age)? 1 : -1;
});


//Sort by ES6 arrow function
 people.sort((a,b)=>{
   return   (a.Age > b.Age)? 1 : -1;
});

Sorted array by age:
>people

0: {Name: "Steve Liu", Age: 12}
1: {Name: "Jack Lee", Age: 21}
2: {Name: "Jack Ma", Age: 31}
3: {Name: "Alice  Xu", Age: 42}