In regards to my previous question (code is still giving me trouble): React: Javascript assignment not updating object
Code Here https://codesandbox.io/s/github/nieroda/js_err
You can see the object I have on line 2. There is no mutation that occurs between 2 and 5 although the print output is different (as seen below) leading me to believe that the code is being executed out of order.
codeBreaker.js:108
1. console.log("BEFORE")
2. console.log(gameBoardCopy[currentRow])
3. console.log("END")
let copy = this.state.gameBoard[currentRow].slice()
4. console.log("Copy Start")
5. console.log(copy)
6. console.log("Before Assignment")
copy[4] = { numColorMatch: 2, numExactMatch: 2 }
7. console.log("After Assignment")
8. console.log(copy)
9. console.log("copy end")
Looking at the output
- BEFORE
2.
0: "BlueViolet"
1: "BlueViolet"
2: "BlueViolet"
3: "BlueViolet"
4: {numColorMatch: 0, numExactMatch: 0}
- END
- Copy Start
5.
0: "BlueViolet"
1: "BlueViolet"
2: "BlueViolet"
3: "BlueViolet"
4: {numColorMatch: 2, numExactMatch: 2}
- Before Assignment
- After Assignment
0: "BlueViolet" 1: "BlueViolet" 2: "BlueViolet" 3: "BlueViolet" 4: {numColorMatch: 2, numExactMatch: 2}
copy end
I cant figure out what is causing this, tips appreciated. Thanks