Array a
[{key:1,name:'name1'},{key:2,name:'name2'},{key:3,name:'name3'},{key:4,name:'name4'},{key:5,name:'name5'}]
Array b is part of array a
[{key:1,name:'name1'},{key:2,name:'name2'}]
Array c is modified based on array b
[{key:1,name:'name11'},{key:22,name:'name22'}]
Now the final result is needed: key:1 is modified, key:2 is deleted, key:3, key:4, key:5 are retained without change, key:22 is added
[{key:1,name:'name11'},{key:3,name:'name3'},{key:4,name:'name4'},{key:5,name:'name5'},{key:22,name:'name22'}]
Please tell me how to implement this logic
Do you want to compare or merge? Deepmerge is very convenient for merging
The extend method is similar to git’s merge
Writing it like that should get the result you want in the end
If you can’t find a good tool, or don’t want to pollute the namespace, then decouple the array, which should meet your requirements
I’ll give you a piece of code to imagine (only suitable for merging with arrays). Just take the following code to the console and output it
Then modify it to suit your needs: