#let cloning variable instead of modifying original

7 messages · Page 1 of 1 (latest)

fallen stag
#

I have an array of objects which contain a count variable, when I use

let ingredientCount = userItems.find(item => item.objectId == recipeIngredients[ingredient].item)?.count
                        ingredientCount -= recipeIngredients[ingredient].count;

the actual count in userItems doesn't get changed, the ingredientCount one does instead. any possible fixes or workarounds?

shell sierra
#

don't extract out the count property, you need to mutate the object

#
let ingredient = userItems.find(item => item.objectId == recipeIngredients[ingredient].item);
ingredient.count -= recipeIngredients[ingredient].count;
#

oh looks like that's a naming conflict

#

eh, you'd have to solve that either way

fallen stag
#

okay

#

thank you :D