0

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

Mohammad Usman
  • 30,882
  • 16
  • 80
  • 78
  • Hello, welcome to StackOverflow. In order to increase your chances of receiving a positive response to your query please read and consider the points raised in the [how to ask](https://stackoverflow.com/help/how-to-ask) section of this site. – Andrew Hardiman Jan 14 '21 at 08:57

1 Answers1

1

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; }
Mohammad Usman
  • 30,882
  • 16
  • 80
  • 78