3

I'm having two objects(say obj1 and obj2) If I change obj1 it is affecting in obj2 also. I'm trying to change the multiple['w']=10. Is there any way for copying object without affecting in second object i.e obj2

let obj1={ 
  "director":{
    "data":[
      "multiple":{
        "w":1
      }
     ]
   }
}

let obj2={...a}
Syed mohamed aladeen
  • 6,507
  • 4
  • 32
  • 59
  • 2
    `{...a}` makes a shallow copy - it will only take the first level of the object properties. And since they are objects themselves, you get references to the same objects. – VLAZ Jun 24 '19 at 07:48

0 Answers0