Node Js + Express + Ejs. Cannot Read Property 'option0' Of Undefined
app.js var options = { option0: 11, option1: 'option1', option2: 'option2', option3: 'option3', option4: 'option4', option5: 'option5', option6: 'option6', option7: 'option7', opti
Solution 1:
You have passed the options
as a reference object for the property opt.So opt
will now point to { option0: 11, option1: 'option1', ...}
and your render function becomes
res.render('main', {opt : { option0: 11, option1: 'option1', ...}});
So when you try to access opt.options.option0
, opt.options
becomes undefined and throws error
Thus you should be using `
<% for (let i in opt) { %>
<% optionName = 'option' + i %>
<optionvalue="<%= i %>"><%= opt[i] %></option>
<% } %>
`
Post a Comment for "Node Js + Express + Ejs. Cannot Read Property 'option0' Of Undefined"