I'm trying to sort an array of objects in JS, but for some reason it doesnt work :(
This is the code I'm running:
let myArr = [{"name": "a", "age": 21}, {"name": "b", "age": 18}, {"name": "c", "age": 20}];
console.log(myArr.sort((a, b) => {
return a["age"] > b["age"];
}))
The output is the same array as it was declared:
[
{ name: 'a', age: 21 },
{ name: 'b', age: 18 },
{ name: 'c', age: 21 }
]
When I looked it up it seemed like it's written as it should, not really sure what went wrong.
Any idea what I did wrong?