I have api weather data being passed to my ejs template. I have a conditional statement to check to see if any api data exists. Regardless, I always get the following error:
Cannot read property 'temps' of undefined
The conditional statement if within a script tag.
<script>
if ( JSON.parse('<%-locals.forecast.temps[0]%>') != undefined){
console.log('there is data');
var height = 500;
var width = 800;
var margins = {
left: 40,
top: 40,
right: 40,
bottom: 40
}
var barData = [
{strength:JSON.parse('<%-locals.forecast.temps[0]%>')},
{strength:JSON.parse('<%-locals.forecast.temps[1]%>')},
{strength:JSON.parse('<%-locals.forecast.temps[2]%>')},
{strength:JSON.parse('<%-locals.forecast.temps[3]%>')},
{strength:JSON.parse('<%-locals.forecast.temps[4]%>')},
{strength:JSON.parse('<%-locals.forecast.temps[5]%>')},
{strength:JSON.parse('<%-locals.forecast.temps[6]%>')},
{strength:JSON.parse('<%-locals.forecast.temps[7]%>')},
{strength:JSON.parse('<%-locals.forecast.temps[8]%>')},
{strength:JSON.parse('<%-locals.forecast.temps[9]%>')},
]