I am rendering an EJS template with an array. But inside the script I can’t access the data. How do I access that data inside a script ?
API CODE
app.get('/', (req, res) => {
var countries = [
{
name: 'america',
cities: [
'New york',
'Los Angeles'
]
},
{
name: 'india',
cities: [
'Delhi',
'Mumbai'
]
}
]
res.render('home', {
countries
});
});
JS SCRIPT
<script>
function populate(sel1, sel2) {
console.log('funcc');
console.log(countries);
}
</script>
The error in chrome console is:
Uncaught ReferenceError: countries is not defined