I am trying to sort the given array by the property "title"
how can I sort it? please help on how can I solve it. thanks.
data = [
{
_index: 'yo',
_type: 'sample1',
_id: '201',
_score: null,
_source: {
type: 'digi',
title: 'The Happy',
description: 'san',
image: 'good.jpg',
},
sort: [ sam ]
},
{
_index: 'ya',
_type: 'sample2',
_id: '201',
_score: null,
_source: {
type: 'sam',
title: 'The lonely',
description: 'san',
image: 'y.jpg',
},
sort: [ sam ]
},
{
_index: 'yi',
_type: 'sample3',
_id: '201',
_score: null,
_source: {
type: 'sam',
title: 'The Angry',
description: 'sam',
image: 'x.jpg',
},
sort: [ sam ]
}
]
thanks
this is what I am trying
data.sort(function (x, y) {
let a = x._source.title.toUpperCase(),
b = y._source.title.toUpperCase();
return a == b ? 0 : a > b ? 1 : -1;
});
console.console(data);
But i am failing to access title.