I have an array of objects, and want to change the value of each key - I have a for…in loop inside of a for loop to go through the array. Any thoughts on why the original array is unchanged?
key in the loop is its own variable with a string value. It’s not a reference to some part of an object from before. That’s why when you assign something else to it here
Rather than using a for ... in ..., you could use the array/object.forEach() nethod. You can add an arguement that returns the index for and array or key for an object:
Sorry for bumping this, but I realised thst my post was incorrect. object.forEach()does not work. Instead, use Object.entries(object).foreach([key, value] => {...});.