javascript 如何对两个数组进行比较

数组a

[{key:1,name:'name1'},{key:2,name:'name2'},{key:3,name:'name3'},{key:4,name:'name4'},{key:5,name:'name5'}]

数组b是在数组a的一部分

[{key:1,name:'name1'},{key:2,name:'name2'}]

数组c是在数组b的基础上进行修改

[{key:1,name:'name11'},{key:22,name:'name22'}]

现在需要最后的结果为key:1被修改,key:2被删除,key:3,key:4,key:5无变化保留,key:22被添加

[{key:1,name:'name11'},{key:3,name:'name3'},{key:4,name:'name4'},{key:5,name:'name5'},{key:22,name:'name22'}]

请问一下如何才能实现这个逻辑


繁花如伊
浏览 409回答 1
1回答

慕丝7291255

使用lodash 的_.differenceWith(a, b, _.isEqual).concat(c)解决了
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript