This is really trivial, but I'm looking for a preferred way and can't seem to find it.
I have a object, like this:
const input = {
aaa: "bee",
foo: "bar",
fizz: "buz",
(...)
}
How do I change it to:
const input = {
aaa: "bee",
foo: "CHANGED",
fizz: "buz",
(...)
}
Without using assignment e.g input.foo = "CHANGED"
?
I'm setting a state in React so I wanted to do something like setState(...input, foo: "CHANGED")
but I can't use ...
as it's not an array. What am I missing? Is there even an elegant way for what I'm looking for? Do I have to map? Or is there a one liner?