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

342
Vistas
How do I iterate through object in order to display the values on EJS

I have a problem with iterating objects on EJS. I am connected to a DB on the backend, and I can console log the objects but when I run it through the front end, I get a result of [Object]

Here is the code on my code in the backend

app.get('/usageData', (req, res) => {

    tableSvc.queryEntities('usageData', query, null, function (error, result, response) {
        if (!error) {

            Object.keys(result).forEach(function(key){
                const final=result[key]
                res.render("usage",{final})
            })
        } else {
            console.log(error)
        }
    });
});

And on EJS:

<ul>
  <table >        
      <table class="table table-hover">
          <thead>
            <tr class="indexs">
              <th scope="col">PartitionKey</th>
              <th scope="col">RowKey</th>
              <th scope="col">Action</th>
              <th scope="col">SelectedReports</th>
              <th scope="col">reportInterval</th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <% for(var i in final) { %>  
                <tr style="font-size: 15px">
                  <td><%= final[i].PartitionKey %>&ensp;</td>
                  <td><%= final[i].RowKey %>&ensp;</td>
                  <td><%= final[i].Action %>&ensp;</td>
                  <td><%= final[i].SelectedReports %>&ensp;</td>
                  <td><%= final[i].reportInterval %>&ensp;</td>
                 </tr>
              <% } %>

            </tr>
          </tbody>
        </table>
  </table>
</ul>

What is displaying on localhost

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Instead of calling res.render() in each loop iteration, build an array of data and pass that only once

if (error) {
  console.error(error)
  return res.status(500).send(error)
}

res.render("usage", {
  final: Object.values(result)
})

Also, don't use for..in to iterate arrays

<tbody>
  <% for(const usage of final) { %>
    <tr style="font-size: 15px">
      <td><%= usage.PartitionKey %>&ensp;</td>
      <td><%= usage.RowKey %>&ensp;</td>
      <td><%= usage.Action %>&ensp;</td>
      <td><%= usage.SelectedReports %>&ensp;</td>
      <td><%= usage.reportInterval %>&ensp;</td>
    </tr>
  <% } %>
</tbody>
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