简体   繁体   中英

How do i display on render instead of console.log in node.js

I have already sorted the objects like the link below. My next step is to be able to use the sorted object so i can use it in to display on my render rather than just console.log() .

I'm not sure if putting it back into an object is the approach. Would appreciate if anyone can help me out. Thanks

 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 }); 

byLikes can be passed to render method as below. In the template, it can be accessed via imglikes property.

res.render('reload', {
  imglikes: byLikes, 
  postername: sortednamehere
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM