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
How to merge 2 objects into one - javascript

I need help with solution on this. I have two objects: Input:

obj1 =  [{name:A}, {name:B}, {name:C}...,]
obj2 =  [{value:1}, {value:2}, {value:3}...,]

And i need to make from these 2 objects one. Output:

obj3 = [{A:1}, {B:2}, {C:3}...,]

Anybody know how to merge obj and obj2 to one? Thanks!

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

If you have consitent nameing, you could map with index.

const
    names = [{ name: 'A' }, { name: 'B' }, { name: 'C' }],
    values = [{ value: 1 }, { value: 2 }, { value: 3 }],
    result = names.map(({ name }, i) => ({ [name]: values[i].value }));

console.log(result);

about 4 years ago · Santiago Trujillo Report

0

You could do this

const obj1 = [{name:'A'}, {name:'B'}, {name:'C'}];
const obj2 = [{value:1}, {value:2}, {value:3}];

const merged = Array.from({length:Math.min(obj1.length, obj2.length)}, (_,i) => {
  return { [obj1[i].name]: obj2[i].value };
});

console.log(merged);

about 4 years ago · Santiago Trujillo 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!