1.判断对象是否为空
var obj = {};
console.log(JSON.stringify(obj) === "{}");//true
2.进行对象的深拷贝
var obj = {
name: 'yhguo',
age: 18,
hobbies: ['fe','ld','mv'],
family: {
father: 'dd',
mother:'mm'
}
}
//利用JSON复制一个副本
var objCopy = JSON.parse(JSON.stringify(obj));
console.log(obj)
console.log(objCopy)
//改变副本
objCopy.age = 22;
objCopy.hobbies.push('gz');
objCopy.family['brother']='sb';
console.log(obj)
console.log(objCopy)
以上:改变objCopy
不会改变obj
。