So I have this array of objects
[
{
'1485958472927784961': {
name: 'bruno fiverr',
points: 6,
user_id: '1485958472927784961',
tweets: [Array]
},
'1414575563323420679': {
name: 'ju',
points: 7,
user_id: '1414575563323420679',
tweets: [Array]
}
}
]
and I would like to sort this array by the number of points the user has. I am trying to get it working using array.sort with the following function:
var top10 = array.sort(function(a, b) { return a.points > b.points ? 1 : -1; }).slice(0, 10);
but all I get is the same array from start. is that possible?
.slice(0, 10`). That must be a copying error or you'd get a syntax error..slice(0, 10);Object.values(array[0]).sort...