array-objects-merge
Merge arrays of objects where object are the same based on your own defined key
Install
npm i -S array-objects-merge
Usage
Merge many arrays of objects only write
const arrMerge = ; const opt = key: 'id' ; // key equals to 'id' is by defaultconst merge = ; // so you can do onlyconst merge = ;
The first opts
object is required, don't try to skip or array-objects-merge
skip your first source
Example
Make a file and insert the next content and run:
const arrMerge = ; const source1 = id: 1 name: 'Andrea' id: 2 name: 'Marlen' id: 3 name: 'Mare' id: 4 name: 'Elyn' ; const source2 = id: 1 age: 15 id: 2 age: 23 id: 3 age: 17 id: 4 age: 19 ; const source3 = id: 1 hobbies: 'dancing' 'movies' 'write' 'yoga' id: 2 hobbies: 'ballet' 'dancing' 'athletics' 'running' id: 3 hobbies: 'soccer' 'volleyball' id: 4 hobbies: 'running' 'swimming' 'study' ; // merge by id propertyconst merge = ; console;
output:
[ , , , ,]
License
MIT. Copyright (c)