Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

198
Views
mapping when using conditional statement

Hope someone can help,

On my site a user can log in and post a notice to the home page, they can then see all their notices and the user that posted the notice.

To show the notice author I am using the below map.

<% notices.map(notice => notice.author.username ) %>
<%= notice.author.username %>

Then I'm trying to say if there is no notice author (as in that user was deleted from the database) i want it to say "Author Unknown"

 <% if (!notice.author.username) { %>
     <p>Author Unknown</p>
 <% } else {%>
      <% notices.map(notice => notice.author.username ) %>
      <%= notice.author.username %>
 <% } %>

but the map seems to stop working in the conditional statement, any idea's???

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Use,

<%- notices.map(notice => notice.author.username ) %>

Instead,

<% notices.map(notice => notice.author.username ) %>

The Javascript functions should be wrapped around <%- %>

If that does not work then ,

Try using for loop or forEach.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!