In a javascript object, is it possible to set property values of undefined nested keys by only using property accessors (e.g. dot notation or bracket notation)?
Lodash's _.set function (and T.J. Crowder's answer) is similar to what I want, but the structure of the code is different, i.e., _.set(state, "some.future.key", "baz")
.
Are there any libraries that would allow me to directly set the values, i.e., state.some.future.key = "baz"
?
Ideally I would want the state to automatically assume the shape of:
state = {
some: {
future: {
key: "baz"
}
}
}