Skip to main content
export declare function filterEmptyValues<T>(input: { data: T }): T;
Recursively filters out empty values from nested objects and arrays. This function removes the following empty values:
  • null and undefined values
  • Empty strings (after trimming whitespace)
  • Empty arrays
  • Empty objects
  • Arrays and objects that become empty after filtering their contents

Examples

import { filterEmptyValues } from "@intuned/browser";
export default async function handler(params, page, context){
filterEmptyValues({ data: { a: "", b: "hello", c: null } }) // Returns { b: "hello" }
filterEmptyValues({ data: [1, "", null, [2, ""]] }) // Returns [1, [2]]
filterEmptyValues({ data: { users: [{ name: "" }, { name: "John" }] } }) // Returns { users: [{ name: "John" }] }
}

Arguments

input
Object
required
The input object containing the data to filter

Returns: T

Filtered data structure with empty values removed