let a = {
name: "Hobby",
hobby: {
sport: 'tennis',
game: 'switch'
}
};
// 先將物件轉為純文字,再轉回物件
const b = JSON.parse(JSON.stringify(a))
a.hobby.game = 'ps5'
console.log('a:', a)
console.log('b:', b)
console.log('a === b', a===b)
/* console結果
a: {
name: "Hobby",
hobby: {
sport: 'tennis',
game: 'ps5'
}
}
b: {
name: "Hobby",
hobby: {
sport: 'tennis',
game: 'switch'
}
}
a === b false
*/
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.