The loop variable name only exists during the current round of the loop. It’s a copy of the array element and not a reference. I like using for (const name of myArray) to always remind myself of that fact.
One way to solve this problem in the exercise is to use a forEach() loop in the form:
myArray.forEach(function(element, index) {
/* your code */
});
Now you can use myArray[index] inside the loop to assign your new value to the actual array element.
I hope that helps. Feel free to ask more questions.
Hi Michael,
Thanks for the explanation, and the welcome!
I’ll have a play around with myArray.forEach and "for (const x of myArray) to make sure I’ve got the distinction.
Thanks again!
Davva