Last active
February 28, 2021 03:10
-
-
Save stordahl/d5081c68961fdf7a721c93a653c42671 to your computer and use it in GitHub Desktop.
a quick function to merge two arrays of objects where a child from one array share a value (like an ID) with a single child of the other array
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
// note: to use this function, replace '.id' in line 4 | |
// with the property youre using to match children | |
const mergeById = (a1: Array<object>, a2: Array<object>) => | |
a1.map(itm: object | null => ({ | |
...a2.find(e: object | null => (e.id === itm.id)), | |
...itm | |
})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment