Sets an objects key by keypath array then returns the object.
If keypath does not have any keys, the object will not be mutated, and the value to assign will just be returned.
If the path does not exist (the path is deeper than the object), it will be created. This WILL overwrite existing values unless they are objects or arrays that can't be written to with the given string, in those cases, careful, it WILL THROW.
constobj = { a: { b: ["c"]} } // mutates and returns the mutated obj set(obj, ["a", "b", 0], "d") // obj.a.b[0] is now "d"
constobj2 = {} set(obj2, ["a", "b", "c"], "d") // obj2.a.b.c is now "d"
constobj3 = {a:"in the way"} set(obj3, ["a", "b", "c"], "d")
constobj4 = {a:"in the way"} set(obj4, ["a", "b"], "d") // throws (we can't create a property b on a string)
Sets an objects key by keypath array then returns the object.
If keypath does not have any keys, the object will not be mutated, and the value to assign will just be returned.
If the path does not exist (the path is deeper than the object), it will be created. This WILL overwrite existing values unless they are objects or arrays that can't be written to with the given string, in those cases, careful, it WILL THROW.