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

126
Views
How to assign keys to items in an object array?

What is the best way to turn

{"john":15, "alex":19, "mark":19, "luke":12}

into

const data = [
  { name: "john", value: 15},
  { name: "alex", value: 19},
  { name: "mark", value: 19},
  { name: "luke", value: 12},
];

Thanks any help is appreciated

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

can solve using map on the object entries

const a = {"john":15, "alex":19, "mark":19, "luke":12}

const res = Object.entries(a).map(([name,value]) => ({name,value}))

console.log(res)

about 4 years ago · Juan Pablo Isaza Report

0

I think the best way is using Object.entries & reduce :

const obj = { john: 15, alex: 19, mark: 19, luke: 12 };
const array = Object.entries(obj).reduce((acc, curr) => {
  const [ name, value ] = [curr[0],curr[1]];
  return acc.concat({ name, value });
}, []);
console.log(array);

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!