✅ – Axel (Rinkusu) – 20-53 Oct 30
Hi, can someone explains me how is it possible that every color is set to 'blue' after this please ?
11 Replies
@Rinkusu show
newTiles
array pleasehow is it possible ? xD
The thing is that your array contains of a single object reference, which - despite having assigned different color each iteration ( you can validate it by
console.log(elem.color)
below the assignment) - at the end of the loop gets assigned one color, and it's so remaining "clones" have the same value
If you want it to work "properly" then use .map()
instead of .forEach()
and return a fresh object on every iteration
Ok, I reworked and got this:
"Cannot set properties of undefined (setting 'color')"
Because first, "piece" is undefined. So how can I set it to an object with a color attribute inside of it please ?$
?
optional chaining operator?
!mdn optional chainingno it would be an invalid left-assignement expression I guess
it works like this:
thx anyway !
This question has an answer! Thank you for helping 😄
If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/565213527673929729/1036382237714829392
This thread hasn’t had any activity in 12 hours, so it’s now locked.
Threads are closed automatically after 12 hours. If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/565213527673929729/1036382237714829392
Question not getting answered? Maybe it's hard to answer, or maybe you asked at a slow time. Check out these resources for help asking a good question:
https://stackoverflow.com/help/how-to-ask
http://wp.me/p2oIwo-26