Home > front end >  Array of objects to sort
Array of objects to sort

Time:12-07

There are an array of objects
Var array=[
{name: 'a', age: 3},
{name: "c", the age: 1},
{name: 'b', age: 2}
]

Request the name is ascending, the age is descending
Can you tell me how to solve? thank you

CodePudding user response:

Const array=[
{name: "a", the age: 3},
{name: "c", the age: 1},
{name: "b", the age: 2},
];
Array. Sort ((x, y)=& gt; {
Return x.n ame. LocaleCompare (y.n ame);
});
The console. The log (array);
  • Related