尝试查看是否有任何JavaScript库功能可以合并两个json对象的特定键的值
var x ={ "student-marks":{'math':1,'physics':5} }; var y ={ "student-marks":{'chemistry':3,'history':2} };
使用$ .extend和$ .merge给出以下结果
$.extend({},x,y) leads to { "student-marks":{'chemistry':3,'history':2} } $.merge(x,y) leads to { "student-marks":{'math':1,'physics':2} }
我正在寻找的是{ "student-marks":{'math':1,'physics':5, 'chemistry':3,'history':2} }
{ "student-marks":{'math':1,'physics':5, 'chemistry':3,'history':2} }
您想深入扩展
$.extend(true, {}, x, y);