@vsokolov/utils - v0.32.0
    Preparing search index...

    Function filterFalsyFromObject

    • Removes falsy or empty values (null, undefined, '', 0, false, etc.) from a plain object or an array of objects.

      • If you pass an object, returns a new object with falsy values removed.
      • If you pass an array, returns a new array of objects with each item filtered.

      Type Parameters

      Parameters

      • obj: T

        An object or array of objects to filter.

      Returns T

      A filtered object (or array of filtered objects) of the same shape.

      filterFalsyFromObject({ a: 1, b: '', c: null });
      // => { a: 1 }

      filterFalsyFromObject([{ a: 1, b: '' }, { a: 0, b: 'ok' }]);
      // => [{ a: 1 }, { b: 'ok' }]
    • Removes falsy or empty values (null, undefined, '', 0, false, etc.) from a plain object or an array of objects.

      • If you pass an object, returns a new object with falsy values removed.
      • If you pass an array, returns a new array of objects with each item filtered.

      Type Parameters

      Parameters

      • arr: T[]

      Returns T[]

      A filtered object (or array of filtered objects) of the same shape.

      filterFalsyFromObject({ a: 1, b: '', c: null });
      // => { a: 1 }

      filterFalsyFromObject([{ a: 1, b: '' }, { a: 0, b: 'ok' }]);
      // => [{ a: 1 }, { b: 'ok' }]