I have successfully sorted the objects as shown in the link below. My next challenge is to integrate the sorted object into my render function rather than just using console.log()
.
I'm uncertain if converting it back into an object is the right approach. Any assistance on this matter would be greatly appreciated. Thank you.
var byLikes = [
{ name: 'herman', Like: 5 },
{ name: 'tabitha', Like: 3 },
{ name: 'juags', Like: 1 },
{ name: 'ukiq', Like: 4 },
{ name: 'limau', Like: 10 },
{ name: 'kwe', Like: 6 }
];
byLikes.sort(sortByLike);
function sortByLike(a, b) {
var result = 0;
if (a.Like > b.Like) { result = 1; }
if (b.Like > a.Like) { result = -1; }
return result;
}
byLikes.forEach(function (cat) {
console.log(cat);
});
res.render('reload', { imglikes: sortedlikedhere, postername: sortednamehere });