samedi 16 mai 2020

Error: variable is not defined in ejs if statement

I have an ejs file with the following code in my script section:

<% for (i = 0; i < comments.length; i++) { %> 
   var chr = [id1, id2, id3]
   console.log(chr)
   <% if (comments[i].displayed === false || chr.includes(comments[i]._id) === true) { %>
      //the rest of my code
   <% } %>
<% } %>

Without the second condition in the if statement (chr.includes(comments[i]._id) === true), the console.log does print out the chr array and the code inside if statement runs without an error, but when I include this second condition, I get an error that "chr is not defined". comments are coming from app.js, but chr is an array that I am defining here in the loop. What am I doing wrong here?

Thanks!

Aucun commentaire:

Enregistrer un commentaire