Options
All
  • Public
  • Public/Protected
  • All
Menu

External module "array/compact"

Index

Functions

Functions

compact

  • compact<T>(arrayToCompact: T[]): T[]
  • Filters falsy values of the given array

    • does not modify the original array
    • Values to be filtered: [undefined, null, "", 0, false, NaN]

    Example usage:

    import { compact } from "@thalesrc/js-utils/array";
    
    const arr = [undefined, "", false, 0, 1, "1"];
    const compacted = compact(arr); // [1, "1"];
    

    Example as Array Prototype:

    import "@thalesrc/js-utils/array/proto/compact";
    
    const arr = [undefined, "", false, 0, 1, "1"];
    const compacted = arr.compact(); // [1, "1"];

    Type parameters

    • T

      type of array

    Parameters

    • arrayToCompact: T[]

      array to compact

    Returns T[]

    a new compacted array

Generated using TypeDoc