I want to sort an array of objects in TypeScript which looks like this:
[
{
"title": "Picture3.jpg",
"targetRange": "B2",
"type": "Bitmap"
},
{
"title": "Picture2.jpg",
"targetRange": "A2",
"type": "Bitmap"
},
{
"title": "Picture1.jpg",
"targetRange": "A1",
"type": "Bitmap"
}
]
I want to have my objects sorted after the targetRange in following order: A1, A2, B2
I refered to this question, but it won't sort it in any way.
How can I sort them by the value of targetRange in TypeScript?
I tried the following things already:
this.objs.sort((a, b) => a.targetRange!.localeCompare(b.targetRange!));
and
this.objs.sort((a,b) => (a.targetRange! < b.targetRange!) ? 1 : ((b.targetRange! > a.targetRange!) ? -1 : 0))```