There is an array which looks like this:
[
{
_id: 'xxnQt5X8pfbcJMn6i',
order: 2
},
{
_id: 'X8pfbcJxxnQt5Mn6i',
order: 1
},
{
_id: 'Qt5X8pfxxnbcJMn6i',
order: 3
}
]
Now I need to sort the objects of this array by the order
value. I tried to do this:
array.sort((a, b) => {
return (a.order > b.order)
? 1
: (b.order > a.order)
? -1
: 0
})
But first it looks to me a bit to complicated for just sorting by an integer value and second it gives me the error TypeError: Cannot assign to read only property '1' of object '[object Array]'