格式化輸出:code
let obj = { a: 'a1', b: 'b1' }; JSON.stringify(obj, null, 2); //{ "a": "a1", "b": "b1" }
巧用深拷貝:string
let obj = { a: 'a1', b: 'b1' }; let copy = JSON.stringify(obj); let copyObj = JSON.parse(copy); copyObj.c = 0; //{a: "a1", b: "b1", c: 0} //{a: "a1", b: "b1"}
再有發現會陸續添加進來copy