Foundry Virtual Tabletop - API Documentation - Version 14
    Preparing search index...

    Function mergeObject

    • Update a source object by replacing its keys and values with those from a target object.

      Parameters

      • original: object

        The initial object which should be updated with values from the target

      • Optionalother: object = {}

        A new object whose values should replace those in the source

      • Optionaloptions: {
            applyOperators?: boolean;
            enforceTypes?: boolean;
            inplace?: boolean;
            insertKeys?: boolean;
            insertValues?: boolean;
            overwrite?: boolean;
            recursive?: boolean;
        } = {}

        Additional options which configure the merge

        • OptionalapplyOperators?: boolean

          Control whether to apply the effects of DataFieldOperator values (if true) or retain those operators (if false) in the resulting merged object.

        • OptionalenforceTypes?: boolean

          Control whether strict type checking requires that the value of a key in the other object must match the data type in the original data to be merged.

        • Optionalinplace?: boolean

          Control whether to apply updates to the original object in-place (if true), otherwise the original object is duplicated and the copy is merged.

        • OptionalinsertKeys?: boolean

          Control whether to insert new top-level objects into the resulting structure which do not previously exist in the original object.

        • OptionalinsertValues?: boolean

          Control whether to insert new nested values into child objects in the resulting structure which did not previously exist in the original object.

        • Optionaloverwrite?: boolean

          Control whether to replace existing values in the source, or only merge values which do not already exist in the original object.

        • Optionalrecursive?: boolean

          Control whether to merge inner-objects recursively (if true), or whether to simply replace inner objects with a provided new value.

      • Optional_d: number = 0

        A privately used parameter to track recursion depth.

      Returns object

      The original source object including updated, inserted, or overwritten records.

      mergeObject({k1: "v1"}, {k2: "v2"}, {insertKeys: false}); // {k1: "v1"}
      mergeObject({k1: "v1"}, {k2: "v2"}, {insertKeys: true}); // {k1: "v1", k2: "v2"}
      mergeObject({k1: {i1: "v1"}}, {k1: {i2: "v2"}}, {insertValues: false}); // {k1: {i1: "v1"}}
      mergeObject({k1: {i1: "v1"}}, {k1: {i2: "v2"}}, {insertValues: true}); // {k1: {i1: "v1", i2: "v2"}}
      mergeObject({k1: "v1"}, {k1: "v2"}, {overwrite: true}); // {k1: "v2"}
      mergeObject({k1: "v1"}, {k1: "v2"}, {overwrite: false}); // {k1: "v1"}
      mergeObject({k1: {i1: "v1"}}, {k1: {i2: "v2"}}, {recursive: false}); // {k1: {i2: "v2"}}
      mergeObject({k1: {i1: "v1"}}, {k1: {i2: "v2"}}, {recursive: true}); // {k1: {i1: "v1", i2: "v2"}}
      mergeObject({k1: "v1", k2: "v2"}, {"k1": new ForcedDeletion()}, {applyOperators: true});   // {k2: "v2"}
      
      mergeObject({k1: {i1: "v1"}}, {"k1": ForcedReplacement.create({i2: "v2"})}, {applyOperators: true}); // {k1: {i2: "v2"}}