Function mergeObjects

  • Uses deep merge way to merge objects. Source will be merged with target.

    Parameters

    • source: AnyObject

      The first object to be merged.

    • target: AnyObject

      The second object to be merged.

    Returns AnyObject

    • The merged object containing the combined properties of source and target.

    Example

    const obj1 = { a: 1, b: 2 };
    const obj2 = { c: 3, d: 4 };
    const result = mergeObjects(obj1, obj2);
    console.log(result); // { a: 1, b: 2, c: 3, d: 4 }

    Example

    const obj1 = { a: 1, b: [1, 2] };
    const obj2 = { b: [3, 4], c: 4 };
    const result = mergeObjects(obj1, obj2);
    console.log(result); // { a: 1, b: [1, 2, 3, 4], c: 4 }

    Example

    const obj1 = { a: { b: 1, c: [1, 2] } };
    const obj2 = { a: { c: [3, 4], d: 4 }, e: 5 };
    const result = mergeObjects(obj1, obj2);
    console.log(result); // { a: { b: 1, c: [1, 2, 3, 4], d: 4 }, e: 5 }

Generated using TypeDoc