Currently working on a website using JavaScript, express.js, ejs, and Node.js and encountered a puzzling issue.
The data is being sent to the frontend in the following manner:
const dataToSend = [
{
id: "ID",
name: "Name"
},
{
id: "ID",
name: "Name"
}
]
res.render('configure', {
array: dataToSend
});
To retrieve it on the frontend using ejs, this method is employed:
<%= array %>
If the array is printed on the frontend, it displays as [object Object]
. Further investigation by printing out typeof('<%= array %>')
indicates that it is of type string.
Although I have come across some related discussions, none seem to provide a solution to this dilemma. Seeking advice on how to handle this situation correctly. Thank you.