iLiA
iLiA

Reputation: 3153

can not parse escaped ejs passed variable

this is my current problem, so i passed stringified array to client from server and i was trying to get it with following code

const stringifiedArray = "<%= array %>";

and it was returning string but when i was trying to parse it, it was returning JSON error "Unexpected Token in position N" and when i changed double quotes with backquote and equation sign with minus sign: (backquote)<%-array%>(backquote) it worked and parsed perfectly, but what is i wanted escaped string to be parsed? how can i do that?

Upvotes: 0

Views: 492

Answers (1)

vaibhav sharma
vaibhav sharma

Reputation: 93

Use

const stringifiedArray = <%- JSON.stringify(array) %>;

instead of

const stringifiedArray = "<%= array %>";

and do not stringify your object or array at server side

Upvotes: 1

Related Questions