@nevware21/ts-utils
    Preparing search index...

    Function setValueByIter

    • Set the named value on the target object where the path is represented by the string iterator or iterable to separate the nested objects of the heirarchy / path to the value.

      For safety, this helper blocks setting any path that includes unsafe keys (__proto__, constructor, or prototype) and will also stop if the traversal reaches an unsafe target such as a built-in prototype object, without writing the final value.

      The order of processing of the iterator is not reset if you add or remove elements to the iterator, the actual behavior will depend on the iterator imeplementation.

      If the passed iter is both an Iterable and Iterator the Iterator interface takes preceedence.

      Type Parameters

      • T

      Parameters

      • target: any

        The target object

      • iter: Iterator<string, any, undefined> | Iterable<string>

        The iter identifying the path of the final key value

      • value: T

        The value to set

      Returns void

      0.9.1

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