TS-Scribe - v0.6.2
    Preparing search index...

    Function pruneObject

    • Recursively removes undefined values from an object or array. This function cleans nested objects and arrays, ensuring that no properties or elements are left with the value undefined.

      Type Parameters

      • T

        The type of the object to be pruned, which extends an object.

      Parameters

      • object: T

        The object or array to prune.

      • Optionaloptions: PruneObjectOptions

        Configuration options.

      Returns T

      The pruned object or array with undefined values removed.

      pruneObject({ a: 1, b: undefined, c: { d: undefined } }); // Returns: { a: 1, c: {} }

      pruneObject([1, undefined, { a: undefined }, [undefined]]); // Returns: [1, {}]

      pruneObject([undefined, undefined]); // Returns: []

      pruneObject({ date: new Date() }); // Returns: { date: DateInstance }

      pruneObject({ a: { b: undefined } }, { deep: false }); // Returns: { a: { b: undefined } }

      pruneObject({ a: [1, undefined] }, { arrays: false }); // Returns: { a: [1, undefined] }