Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

101
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!