Skip to content
Advertisement

nodejs ejs render array object in to table

Good day I need to write a table from a database and i can’t access the values, if the array is greater than 1… If i do it like this:

JavaScript

and on the ejs side it looks like this:

JavaScript

if i use my hardcoded value, it works. But if i try to change the i value to 2 or more, it gives me an error… why is this so?

Many thanks for the help!

Advertisement

Answer

You are initializing your spielzeiten array with a length of 1 and not increasing its size if you have more than one record. Thus, of course if you try to access an spielzeiten[i].spzeit with an index different from 0 you get an error.

You should probably initialize your array as an empty array and add new items during the loop.

JavaScript

You could also use the Array.map function to directly initialize your array

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement