Sort Array of Objects by Property

Descending code snippet

const blogs = [
{ title: 'blog one', likes: 1 },
{ title: 'blog two', likes: 8 },
{ title: 'blog three', likes: 3 }
]
const sortedBlog = blogs.sort((a, b) => {
return b.likes - a.likes
})

Use .localeCompare() to sort by non-ASCII characters

var items = ['réservé', 'premier', 'communiqué', 'café', 'adieu', 'éclair'];
items.sort(function (a, b) {
return a.localeCompare(b);
});
// items is ['adieu', 'café', 'communiqué', 'éclair', 'premier', 'réservé']

To Review