Created
April 18, 2020 01:32
-
-
Save artystable/d23c1a98252cee020ffbe230ce579b68 to your computer and use it in GitHub Desktop.
Very rudimentary script to merge to JS object arrays.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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