Problem 1: Your loop is adding members to your original $colors
array, which is unlikely what you want to be doing. I’d use temporary variables for the original colors and numberlist arrays, so you aren’t contaminating the final $colors
array.
Problem 2: You cannot access the properties of an object within the array before you’ve found the object.
Try the following, using the <Array>.find()
method:
<<set $colornumber = $colors.find(color => color.colorcode === $playerPick).colorcode>>
Though, ideally you’d check to ensure that you’d actually found a value before attempting to access its property. E.g.,
<<set _found = $colors.find(color => color.colorcode === $playerPick)>>
<<if def _found>>
<<set $colornumber = _found.colorcode>>
<</if>>