0

long story short, when I do this:

 setup(props) {
       console.log(props.orders[0].order_line[0].reserved);
       let myOrders = props.orders.map((el) => el);
       myOrders[0].order_line[0].reserved = false; 
       console.log(props.orders[0].order_line[0].reserved,myOrders[0].order_line[0].reserved)
 }

I got this:

true
false false

Maybe I'm missing something basic but I even tried with the spread operator or Object.assign and still got the same result! Does someone knows what it can be?

Rui Silva
  • 1
  • 1
  • Well, what result did you expect? You've got two arrays with the same objects in it, not copies. – tkausl Jan 21 '22 at 01:09
  • Well I haven't tried the JSON.parse(JSON.stringify(o)) method but it seems to do the trick... Thank you. Therefore, I still don't understand why .map, spread operator or Object.assign don't do the job as I always used them before in plain javascript with no trouble at all. – Rui Silva Jan 21 '22 at 01:24
  • They don't do deep clones and never did. `I always used them before in plain javascript with no trouble at all.` Then you never needed a deep clone before. – tkausl Jan 21 '22 at 01:26

0 Answers0