Function setValueByKey

  • Set the named value on the target object where the path may be presented by a string which contains "." characters to separate the nested objects of the heirarchy / path to the value.

    Type Parameters

    • T

    Parameters

    • target: any

      The target object

    • path: string

      The path identifying the location of the final key value

    • value: T

      The value to set

    Returns void

    0.9.1

    let theValue = { };
    setValueByKey(theValue, "Hello.Darkness.my", "old");
    // Resulting Object: { Hello: { Darkness: { my: "old" } } }
    setValueByKey(theValue, "friend", "I've");
    // Resulting Object: { Hello: { Darkness: { my: "old" } }, friend: "I've" }
    setValueByKey(theValue, "come.to.see", "you");
    // Resulting Object: { Hello: { Darkness: { my: "old" } }, friend: "I've", come: { to : { see: "you" } } }