How do I re-arrange how my loop works?

264
August 15, 2017, at 8:20 PM

I am working on a message board and i want the new topics to be the first in line. I am using a forEach loop to print out all the Topics but the new ones are going under the old ones. how do i fix this?

my forEach Code

<% threads.forEach(function(thread){ %> "><%= thread.subject%>
Posted by: -

Answer 1

you can use reverse

<% threads.reverse().forEach(function(thread){ %> "><%= thread.subject%>
READ ALSO
npm install with 2 projects in one docker image

npm install with 2 projects in one docker image

I have a docker container that combines 2 node projects into oneProject A is the statsd project and project B is a postgres backend project that writes to a postgres database using the npm package pg

209
Get Data from POST request on client side

Get Data from POST request on client side

I made a form post request from my react front endIn my express route I handle it, and I send the data to the browser, as such:

324
Webpack builds on production environment

Webpack builds on production environment

In React JS starter kits like the one at https://githubcom/wallacyyy/reactly-starter-kit, I see package

385
Mongoose sends existing document when validation failed

Mongoose sends existing document when validation failed

I have a POST request to create a documentMy problem is that mongoose sets the original document as part of the response when validation fails

275