Modifying a copy of a JavaScript object is causing the original object to change

前端 未结 5 1150
野趣味
野趣味 2020-11-22 05:06

I am copying myObj to tempMyObj

var tempMyObj = myObj;

tempMyObj.entity is an array of objects. I am

5条回答
  •  鱼传尺愫
    2020-11-22 05:37

    deep clone object with JSON.parse() and JSON.stringify

    // Deep Clone
    obj = { a: 0 , b: { c: 0}};
    let deepClone = JSON.parse(JSON.stringify(obj));
    

    refrence: this article

提交回复
热议问题