I have this array of objects:
let ans = [{'a' : 5},{'d' : 3 },{'c' : 0 },{'b' : 4 }];
//Attempt to sort this
ans.sort((a,b)=>{
return Object.keys(a)[0] > Object.keys(b)[0];
});
console.log(ans);
Shouldn't this sort function sort it? If not this how to sort this.
truegets converted to1butfalsegets converted to0instead of-1, hence your sort function is not working correctly.