I'm trying to change the value in userInfo
with userArray
. I tried to change the first value of dictionary by writing Object.values(userInfo)[0] = userArray[0]
but it didn't work. Is there another way to change values in a dictionary?
let userInfo = {'John': money(),'Mary': money(),'Bob': money()}
console.log('Before Dictionary:',userInfo)
let total = 0
let userArray = Object.values(userInfo); //To get dictionary values into array
userArray.forEach(doubleMoney) //Multiply array values by 2
function money(){
randomMoney = Math.floor(Math.random() * 1000000);
return randomMoney
}
function doubleMoney(element,index,array){
array[index] = element * 2
}
Object.values(userInfo)[0] = userArray[0] //Change the first value of dict to first value of array
console.log('Mutiplied array: ',userArray)
console.log('After Dictionary: ',userInfo);