Skip to content

Instantly share code, notes, and snippets.

@artystable
Created April 18, 2020 01:32
Show Gist options
  • Save artystable/d23c1a98252cee020ffbe230ce579b68 to your computer and use it in GitHub Desktop.
Save artystable/d23c1a98252cee020ffbe230ce579b68 to your computer and use it in GitHub Desktop.
Very rudimentary script to merge to JS object arrays.
let one = [
{
id: "aBcDeFgH",
firstName: "Juan",
lastName: "Doe",
age: 32,
},
{
id: "zYxWvUt",
firstName: "Alex",
lastName: "Smith",
age: 24,
},
];
let two = [
{
id: "aBcDeFgH",
occupation: "architect",
address: {
street: "123 Main St",
city: "CityTown",
Country: "USA",
},
},
{
id: "zYxWvUt",
occupation: "receptionist",
address: {
street: "555 Ocean Ave",
city: "Beach City",
Country: "USA",
},
},
];
function myFun(sOne, sTwo) {
let list = [];
for (let index = 0; index < Object.keys(sOne).length; index++) {
const element = sOne[index];
element.address = sTwo[index].address
list.push( element )
}
return list
}
myFun(one, two)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment