How do i sort my objects that contains numbers and other information?
I have 2 objects. The likes that is also link with the information object. Likesobject contains random number while the viewname will be related to likesobject. Next thing is, viewname will be added more and more if there are new names coming in. So it wont just stop at d: link d
Example
var viewnames = {
'a': 'link a',
'b': 'link b',
'c': 'link c',
'd': 'link d'
};
var Likeobject = {
'a': 6,
'b': 1,
'c': 9,
'd': 8
};
Example,
name1 -> 2 likes
name2 -> 5 likes
name3 -> 10 likes
name4 -> 8 likes
name5 -> 12 likes`
After sorting out from highest to lowest,
name5 -> 12 likes
name3 -> 10 likes
name4 -> 8 likes
name2 -> 5 likes
name1 -> 2 likes
var obj1 = [{numLikes: likesobject},{viewerName: viewnames}];
I am not sure if the way I code my object is the right way. Do correct me if I'm wrong. Hope to get solution to my question.