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

138
Views
convert object in to array of json with given keys

I have object like

{ labels: ["city A", "city B"], data: ["Abc", "Bcd"] };

I want to convert above object as below array of json

[
  { labels: "city A", data: "Abc" },
  { labels: "city B", data: "Bcd" },
];
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can achieve it with something like this:

const original = {
  labels: ['city A', 'city B'],
  data: ['Abc', 'Bcd']
};

let merged = [];
const keys = Object.keys(original);
for (let idx = 0; idx < keys.length; idx++) {
  const entry = Object.assign.apply({},
    keys.map((key) => ({
      [key]: original[key][idx]
    }))
  );
  merged.push(entry);
}

console.log(merged);

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!