1. 程式人生 > >js 物件操作

js 物件操作

js裡物件的深拷貝 

let arr = ['8','7','6'];
let arrObj = JSON.parse(JSON.stringify(arr));
arrObj[0] = '9';
console.log(arr); // ['8','7','6']
console.log(arrObj); // ['9','7','6']

js物件的判斷為空{}

let obj = {};
JSON.stringify(obj) == "{}"
console.log(JSON.stringify(obj) == "{}"); // true