I've an object as
const posts = {
"BAhvZrRwcfu":{
"text":"Totally need to try this.",
"user": "heavymetaladam",
vote: 2
},
"BAcyDyQwcXX":{
"text":"Wes. WE should have lunch.",
"user": "jdaveknox",
vote : 3
}
};
is there a way I can sort based on the vote.It seems easier if i make it an array of object
var keys = Object.keys(state.posts); keys.sort((a, b) => { if (a.voteScore < b.voteScore) { return -1; } if (a.voteScore > b.voteScore) { return 1; } // a.voteScore must be equal to b.voteScore return 0; }).reduce((a, v) => { return state.posts[v] }, {})It seems easier if i make it an array of object- yes, you are right on this point, because Objects are not "sortable", arrays are