I need help with solution on this. I have two objects:
Input:
obj1 = [{name:A}, {name:B}, {name:C}...,]
obj2 = [{value:1}, {name:2}, {name: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!
>Solution :
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)}).map((_,i) => {
return { [obj1[i].name]: obj2[i].value };
});
console.log(merged);