Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

200
Visualizações
Array of objects to text based table node.js

So I am querying a sql database and getting a result like

[
  { id: '626916199783071750', birthdays: '10/3' },
  { id: '797279656595947531', birthdays: '01/02' },
  { id: '548976894576849555', birthdays: '3/24' }
]

But it could have more columns or rows so like it could be something like this

[
  { id: '626916199783071750', username: 'whatever', idk: true },
  { id: '797279656595947531', username: 'thing', idk: false},
  { id: '7972656595947531', username: 'idk', idk: true },
  { id: '874596745986988596', username: 'cooldude', idk: false }
]

I want to make it into a table I send to the console, something like

+--------------------+----------+
| ID                 | Birthday |
+--------------------+----------+
| 626916199783071750 | 10/3     |
+--------------------+----------+
| 797279656595947531 | 01/02    |
+--------------------+----------+
| 548976894576849555 | 3/24     |
+--------------------+----------+

Where it adds the formatting and the correct amount of rows/columns. I would use a npm package but I cannot seem to find one that takes an array of objects and outputs a table.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

There's a very handy built-in way of doing this (works on the browser as well) using console.table (Node.js documentation).

console.table([{ a: 1, b: 'Y' }, { a: 'Z', b: 2 }]);

// ┌─────────┬─────┬─────┐
// │ (index) │  a  │  b  │
// ├─────────┼─────┼─────┤
// │    0    │  1  │ 'Y' │
// │    1    │ 'Z' │  2  │
// └─────────┴─────┴─────┘

You can even restrict which properties get printed out:

console.table([{ a: 1, b: 'Y' }, { a: 'Z', b: 2 }], ['a']);

// ┌─────────┬─────┐
// │ (index) │  a  │
// ├─────────┼─────┤
// │    0    │  1  │
// │    1    │ 'Z' │
// └─────────┴─────┘
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda