@alanscodelog/utils
    Preparing search index...

    Function set

    • 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.

      const obj = { a: { b: ["c"]} }
      // mutates and returns the mutated obj
      set(obj, ["a", "b", 0], "d")
      // obj.a.b[0] is now "d"

      obj2 = set(obj, [], {}, {noError:true})
      // obj is still the above, obj2 is {}

      Parameters

      • mutated: any
      • keypath: (string | number)[]
      • val: any

      Returns any