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

188
Views
JS: put all obj's keys together as each new element in an array
const dataArray = [
    { keyA: ["valueA1", "valueA2"] },
    { keyB: ["valueB1", "valueB2"] },
    { keyC: ["valueC1", "valueC2"] },
]

Put all obj's keys together as each new element and match inner array's elements with their respective index order.

The inner array's values are always fetched in the same index's order.

the following intended result explains better what I mean:

[
    {
        keyA: "valueA1",
        keyB: "valueB1",
        keyC: "valueC1",
    },
    {
        keyA: "valueA2",
        keyB: "valueB2",
        keyC: "valueC2",
    }
]
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can do something like this

const dataArray = [{
    keyA: ['valueA1', 'valueA2']
  },
  {
    keyB: ['valueB1', 'valueB2']
  },
  {
    keyC: ['valueC1', 'valueC2']
  },
];
const keys = dataArray.map((data) => Object.keys(data)[0]);
const result = [];

let keyIndex = 0;
let valueIndex = 0;

while (valueIndex < dataArray[0].keyA.length) {
  const obj = {};
  for (keyIndex = 0; keyIndex < keys.length; keyIndex++) {
    obj[keys[keyIndex]] = dataArray[keyIndex][keys[keyIndex]][valueIndex];
  }

  result.push(obj);
  valueIndex++;
}
console.log(result);

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