Thanks again for the help Miguel but I finally cracked it. below is the updated code
let customArray = {
0: {"share": 4, "id":3},
1: {"share": 2, "id":1},
2: {"share": 8,"id":6},
3: {"share": 3, "id":4},
4: {"share": 1, "id":8},
};
let newArray = [];
for(let i in customArray){
let id = customArray[i].id;
let share = customArray[i].share;
newArray.push(Object.assign({},{"share": share, "id":id}));
}
newArray.sort(function (a, b) {
return b.share - a.share;
});
console.log(newArray);
Result: descending order by share with related id
0: "{\"share\":8,\"id\":6}"
1: "{\"share\":4,\"id\":3}"
2: "{\"share\":3,\"id\":4}"
3: "{\"share\":2,\"id\":1}"
4: "{\"share\":1,\"id\":8}"