方法一:
let obj = {"name": "小理有趣","city": "北京","list": [{"course": "语文"},{"course": "数学"}]}
let newObjA = obj; // 未拷贝的
let newObjB = _.cloneDeep(obj); // 拷贝的 // _.clone(obj) 是浅拷贝obj.list[0].course = "戏剧表演";console.log(obj); console.log(newObjA);console.log(newObjB);
打印输出如图:
方法二:
let obj = {"name": "小理有趣","city": "北京","list": [{"course": "语文"},{"course": "数学"}]}
let copyObj = JSON.parse(JSON.stringify(obj));
obj.list[0].course = "戏剧表演";console.log(obj);console.log(copyObj);
打印输出: