I am trying to change the values inside an object in Javascript, Object.values while running a forEach loop would seem to make the most sense to me but Object.keys (obj[key]) actually updated the value on the object. Here is my code to explain better.
This way below works as expected
const usersKey = { user1: 18273, user2: 92833, user3: 90315 }
Object.keys(usersKey).forEach((key) => {
usersKey[key] = usersKey[key]*2
})
console.log(usersKey)
This way below does not update the object
const usersValue = { user1: 18273, user2: 92833, user3: 90315 }
Object.values(usersValue).forEach((value) => {
value = value*2
})
console.log(usersValue)
Why is this? Shouldn't both ways produce identical results?