I have an array of Objects. In some Objects key { liked:true } is present. I wish to sort them as all Objects having liked value on top of the array and remaining after them. There are some objects having key { liked:true }. I wish to sort whole array Objects as those Objects having key {liked : true} comes at the top of array and those which didn't have key {liked :true} will come afterwards.
var arr = [ { e:1, f: 2}, {liked:true, a:1, b: 2},{ g:1, h: 2},{liked:true, c:1, d: 2}]
I have tried this but It didn't work.
arr.sort(function(a, b){
return b.liked
})
I expect that all Objects having key {liked:true} comes on top in array.