I have this on my backend:
app.get('/dashboard', async(req, res) => {
const customers = await stripe.customers.list();
customers.data.forEach(customer => {
// console.log(customer.metadata);
});
res.render('dashboard.ejs', {customer: customers})
console.log(customers)
})
and on my front-end (ejs):
<table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
<thead>
<tr>
<th>NAME</th>
<th>EMAIL</th>
<th>ACTIONS</th>
</tr>
</thead>
<tbody>
<% if(customer.data.length){
for(var i = 0;i < customer.data.length;i++) { %>
<tr>
<script>
let kk = JSON.stringify('<%=customer.data%>')
console.log(kk)
</script>
<td><%=customer.data%></td>
<% }
}else{ %>
<p>err</p>
<% } %>
</tr>
</tbody>
</table>
but when I log kk, it returns [object Object], and the same when I put it out to the screen, as you can see I am doing above. How can I fix this?
you can do
Object.keys(kk)
to get the keys of the object and then access values using the keys.
more complete answer
for key in Object.keys(kk) {
value = kk[key];
console.log(value);
}
you can also use JSON.stringify(kk)