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

169
Views
How to convert multiple object to just one object with Javascript?

As you can see i have a multiple object like "123", "098", and "456", i want all of those object to be inside the object of multiple object.

Example:

var obj = 
{
  "123": {
    "name": "yourname1"
    "class": ["art","math"]
  },
  "098": {
    "name": "yourname2"
    "class": ["art"]
  },
  "456": {
    "name": "yourname3"
    "class": ["math"]
  }
}

output i expected:

{
    "number": "123",
    "name": "yourname1"
    "class": ["art","math"]
  },
  {
    "number": "098"
    "name": "yourname2"
    "class": ["art"]
  },
  {
    "number": "456"
    "name": "yourname3"
    "class": ["math"]
  }
}

How can I achieve this? I'm sorry im not show any javascript code cause until now I have no idea what to do

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

0

You can map the Object.entries since there is 1:1 of the entries to the array item

const obj = {
  "123": { "name": "yourname1", "class": ["art","math"] },
  "098": { "name": "yourname2", "class": ["class1","class2"] },
  "456": { "name": "yourname3" }
};

const arr = Object.entries(obj)
  .map(([key, val]) => ({ "number": key, "name": val.name, "class": val.class || [] }));
console.log(arr)

about 4 years ago · Juan Pablo Isaza Report

0

var obj = {
  123: {
    name: 'yourname1',
  },
  '098': {
    name: 'yourname2',
  },
  456: {
    name: 'yourname3',
  },
};
const obj2 = Object.keys(obj).map(key => ({
  number: key,
  name: obj[key].name,
}));
console.log(obj2);

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!