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

103
Visualizações
Transpose Array of Objects to s

I'm trying to transpose an object, so I can rener them to a table as a single row per product.

data is coming from a MySQL database, I can modify the query so that uses a case for the various products, but it wouldn't be scalable.

Data is coming out like this, which I want to transform/transpose

    [
        {
            label: 'Product 1',
            color: 'green',
            discontinued: 1,
            inventory: 5
        },
        {
            label: 'Product 2',
            color: 'green',
            discontinued: 1,
            inventory: 13
        },
        {
            label: 'Product 2',
            color: 'red',
            discontinued: 1,
            inventory: 1
        },
        {
            label: 'Product 3',
            color: 'green',
            discontinued: 1,
            inventory: 1
        },
            {
            label: 'Product 1',
            color: 'blue',
            discontinued: 1,
            inventory: 0
        },
        {
            label: 'Product 2',
            color: 'blue',
            discontinued: 1,
            inventory: 2
        },
        {
            label: 'Product 3',
            color: 'blue',
            discontinued: 1,
            inventory: 1
        },
    ]

to this:

[
           {
            label: 'Product 3',
            blue: 1,
            green: 1,
            red: 0,
            discontinued: 1,
        }, 
            {
            label: 'Product 2',
            blue: 1,
            green: 13,
            red: 1,
            discontinued: 1,
        },                 {
            label: 'Product 1',
            blue: 0,
            green: 5,
            red: 0,
            discontinued: 1,
        }, 
]

I'm looking over these articles but not sure how to convert it so it can use an object rather than an array

Transform array of objects into a transposed array of objects

https://techbrij.com/convert-column-to-row-javascript-array-pivot

about 4 years ago · Juan Pablo Isaza
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