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

164
Views
merge array object in another normal object

For example i have an array like

const student = [
  { firstName: 'Partho', Lastname: 'Das' },
  { firstName: 'Bapon', Lastname: 'Sarkar' }
];

const profile = [
  { education: 'SWE', profession: 'SWE' },
  { education: 'LAW', profession: 'Law' }
];

Now i want to merge those two object like

const student1 = [
  {
    firstName: 'Partho',
    Lastname: 'Das',
    profile: [{
      education: 'SWE',
      profession: 'SWE'
    }]
  }
];

const student2 = [
  {
    firstName: 'Bapon',
    Lastname: 'Sarkar',
    profile: [{
      education: 'LAW',
      profession: 'Law'
    }]
  }
];

I am new to javascript, i am trying it many ways but couldn't. please help me to solve this using javascript.

Thanks...๐Ÿ™‚ in advance.

about 4 years ago ยท Juan Pablo Isaza
2 answers
Answer question

0

Use Array.map and array destructuring

const student = [ {firstName: 'Partho', Lastname: 'Das'}, {firstName: 'Bapon', Lastname: 'Sarkar'} ];
const profile = [ {education: 'SWE', profession: 'SWE'}, {education: 'LAW', profession: 'Law'} ];

const [student, student2] = student.map((node, index) => ({ ...node, profile: [profile[index]]}));
console.log(student, student2);

about 4 years ago ยท Juan Pablo Isaza Report

0

You can do it like so:

const student = [
  { firstName: 'Partho', Lastname: 'Das' },
  { firstName: 'Bapon', Lastname: 'Sarkar' },
];

const profile = [
  { education: 'SWE', profession: 'SWE' },
  { education: 'LAW', profession: 'Law' },
];

const student0 = [{ ...student[0], profile: [profile[0]] }];
const student1 = [{ ...student[1], profile: [profile[1]] }];

console.log(student0);
console.log(student1);

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!