I am using Nodejs with ejs template. I have an array in my Nodejs backend that looks like this:
array= [false,false,false,false]
Now, if I try to send this to my ejs doing something like
res.render("home",{myarray:array}
and in my ejs(frontend)
let myarray = <%- myarray %>
I get:
Uncaught SyntaxError: Unexpected token false
which upon inspection shows
let myarray = false,false,false,false
However, in my backend if I change
res.render("home",{myarray:array}
to
res.render("home",{myarray:JSON.stringify(array)}
Everything works fine. Myarray now becomes an array again:
[false,false,false,false]
I just do not understand why JSON.stringify helps me send an array from the backend to the front end when I cannot send a regular array.