Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

76
Views
passing data from loop to front-end

I have this function 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})
})

and on my front end:

 <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.length){ 
        for(var i = 0;i < customer.length;i++) { %>
      <tr>
      <td><%=customer[i].NAME%></td>
      <td><%=customer[i].EMAIL%></td>
         <% }
        }else{ %>
            <% } %>
    </tbody>
  </table>

however, i am trying to pass the METADATA to the front end. and within the metadata object, i have name and email. So on the front end, i tried:

<%=customer[i].METADATA.NAME%>

but it returned nothing. and same on the backend. how can i fix this?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

In the comments above, by fetch I mean the term fetch you need to some how connect to your backend to accept the data on front end. You can use ajax, axios, fetch API etc.... Below I used ajax to show how to get data from back end. Feel free to comment if you have any questions?

var data_from_backend;

$.ajax({
  type: 'GET',
  data: 'data_to_send_to_backend',
  url: 'server_URL',
  success: function(getMetadata) {
    $.each(JSON.parse(getMetadata), function(myMetadata) {
      data_from_backend = myMetadata.the_name_of_data_set_on_backend
    })
  },
  error: function(data) {
    console.log('Something went wrong.');
  }
});

console.log(data_from_backend)

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!