I have this array:
array: [
{id: 1, title: 'Thanos', content: '123'},
{id: 2, title: 'Deadpool', content: '456'},
{id: 3, title: 'Batman', content: '789'}
]
and I want it to be sorted by title
key. How do I do that in Javascript
?
I have this array:
array: [
{id: 1, title: 'Thanos', content: '123'},
{id: 2, title: 'Deadpool', content: '456'},
{id: 3, title: 'Batman', content: '789'}
]
and I want it to be sorted by title
key. How do I do that in Javascript
?
array.sort((a, b) => a.title.localeCompare(b.title));