Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

78
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda