Reputation: 1
Input:
const name = [{id:1, first_name: "Sade", age:"30"}, {id:2, first_name: "Jon", age:"40"}];
const ln = [{last_name: "Smith"}, {last_name: "Doe"}];
Output:
const name = [
{id:1, first_name: "Sade", last_name: "Smith", age:"30"},
{id:2, first_name: "Jon", last_name: "Doe", age"40"}
];
Please help me to get this output in nodejs
Upvotes: 0
Views: 51
Reputation: 39322
You can use .map()
and Spread Syntax to get the desired output:
const name = [{id:1, first_name: "Sade"}, {id:2, first_name: "Jon"}];
const lname = [{last_name: "Smith"}, {last_name: "Doe"}];
const output = name.map((o, i) => ({...o, ...lname[i]}));
console.log(output);
.as-console-wrapper { max-height: 100% !important; top: 0; }
Upvotes: 1