Tengo datos como este:
Data = "Time": "06:04:01", location: canada, "user": [ { "name": "Drake", "email": "drake@gmail.com", "age": "16", }, { "name": "jack", "email": "jack@gmail.com", "age": "28", }, { "name": "peter", "email": "sams@gmail.com", "age": "20", }, ]quiero imprimirlos con consola
Quiero recorrer los datos e imprimirlos en una tabla como esta . en el nodo jS
Quiero generar un archivo con fs (biblioteca del sistema de archivos) y generar un archivo html aquí... con etiquetas de tabla:
str ="<table> <th>name</th> <th>email</th> <th>age</th> <td>"; for(let i = 0; i < Data.user.length; i++){ str+= JSON.stringify(Data.user[i].name); } str+= "</td><td>" for(let i = 0; i < Data.user.length; i++){ str+= JSON.stringify(Data.user[i].email); } str+= "</td><td>" for(let i = 0; i < Data.user.length; i++){ str+= JSON.stringify(Data.user[i].age); } str+= "</td><td></table>" return strEstoy obteniendo datos como: este
La mesa y todo está bien, hay algún problema con el bucle o la visualización. Por favor, ayúdame, ¿cómo puedo imprimirlos así ? Gracias
Encuentre la siguiente solución:
str ="<table> <th>name</th> <th>email</th> <th>age</th>"; for(let i = 0; i < Data.user.length; i++){ str+= "<tr><td>"+JSON.stringify(Data.user[i].name)+"</td><td>"+JSON.stringify(Data.user[i].email)+"</td><td>"+JSON.stringify(Data.user[i].age)+"</td></tr>"; } str+= "</table>" return str