I encounter an error on client side while sending a variable using res.Render().
I'd like to send an object with arrays in it:
NodeJs:
var countries_lat_lng = [];
trip.countries.forEach(country => {
var country_lat_lng = {'latlng': CountriesJSON.find(f => f.alpha2Code == country.code).latlng};
countries_lat_lng.push(country_lat_lng);
});
console.log(countries_lat_lng); //value: [ { latlng: [ -27, 133 ] }, { latlng: [ -41, 174 ] } ]
res.render('myView', {
coutriesLatLng: {countries_lat_lng}
});
Javascript:
var countriesMarkers = <%= coutriesLatLng %>;
And I have this following error on chrome:
var countriesMarkers = [object Object]; Uncaught SyntaxError: Unexpected identifier
When I console.log() my countries_lat_lng variable, everything seems to be ok but rendered In javascript I have an error. Many thanks for your help.