Javascript-Lodash/下划线比较两个对象并根据它们的键更改值

Javascript-Lodash/下划线比较两个对象并根据它们的键更改值,javascript,arrays,underscore.js,lodash,Javascript,Arrays,Underscore.js,Lodash,有一个小问题 我需要比较两个对象,并根据这些对象中的相同键将值从第二个对象传递到原始对象 原物 { content: "Old Value", height: 200, id: "15a2d286-d123-1cf0-4e40-b043b055a49f", type: "location", units: "some unit value", width: 200, } 第二个对象 { units: "some unit value", con

有一个小问题

我需要比较两个对象,并根据这些对象中的相同键将值从第二个对象传递到原始对象

原物

{
   content: "Old Value",
   height: 200,
   id: "15a2d286-d123-1cf0-4e40-b043b055a49f",
   type: "location",
   units: "some unit value",
   width: 200,
}
第二个对象

{
   units: "some unit value", 
   content: "New Value"
}
检查合规性不需要钥匙

输出将是这样的

{
   content: "New Value", // changed value
   height: 200,
   id: "15a2d286-d123-1cf0-4e40-b043b055a49f",
   type: "location",
   units: "some unit value", // changed value
   width: 200,
}
使用Lodash或下划线有什么优雅的解决方案吗?

这样就可以了(使用Lodash)

这将达到目的(使用lodash)


你的比较基于什么?
units
值?似乎您只想合并两个对象?您的比较基于什么?
units
值?似乎您只想合并两个对象?如果我可以问一下,u.assignIn和u.merge之间有什么区别?例如,u.merge(source,source2)似乎也在做同样的事情!如果我可以问一下u.assignIn和u.merge之间的区别是什么?例如,u.merge(source,source2)似乎也在做同样的事情!
var source = {
  content: "Old Value",
  height: 200,
  id: "15a2d286-d123-1cf0-4e40-b043b055a49f",
  type: "location",
  units: "some unit value",
  width: 200,
},
source2 = {
  units: "some unit value", 
  content: "New Value"
}
_.assignIn(source , source2 );