jquery 合并两个 json 对象
jQuery.extend( [ deep ], target, object1, [ objectN ] )合并对象到第一个对象
//deep为boolean类型,其它参数为object类型var object1 = { apple: 0, banana: {weight: 52, price: 100}, cherry: 97};
var object2 = { banana: {price: 200}, durian: 100};
实例1:
$.extend(object1, object2); //合并对象,修改第一个对象
object1 === {apple: 0, banana: {price: 200}, cherry: 97, durian: 100} //结果
实例2:
var empty = {}
var object = $.extend(empty , object1, object2); //有target, object1,object2参数
//合并对象到empty中,没有破坏已有的对象(object1)。object===empty
empty === {apple: 0, banana: {price: 200}, cherry: 97, durian: 100}
实例3:
$.extend(true, object1, object2); //合并对象,修改第一个对像 deep==true;
object1 === {apple: 0, banana: {weight: 52, price: 200}, cherry: 97, durian: 100}
此博客已暂停维护,博主已搬家至 https://dukec.cn/