I have a rather strange problem. On server side, I call an an ejs-page by
res.render('index', {varArray: JSON.parse(response)});
When I try to use the variable "varArray" within HTML-Code, everything works fine, e.g.:
<% for (var i = 0; i < varArray.length; i++) { %>
<option value="<%= varArray[i].id %>"><%= varArray[i].name %></option>
<% } %>
BUT: As soon as I want to use the same variable in a function on the same page, I get an error message, that this variable is undefined.
<body>
<script>
function test() {
for (var i = 0; i < varArray.length; i++) {
// do something
}
};
</script>
I hope, someone can help me.