Function arrObjectsToTable

  • Convert an array of objects to a two-dimensional table.

    Type Parameters

    • T

      The type of the values in the objects.

    • E

    Parameters

    • objects: Record<string, undefined | T>[]

      The array of objects to convert to a table.

    • options: {
          emptyCell?: E;
          headers?: string[];
      } = {}

      The options for converting the objects to a table.

      • Optional emptyCell?: E

        An optional value to use for empty cells. If not provided, the function will use undefined.

      • Optional headers?: string[]

        An optional array of strings specifying the headers (property names) to use. If not provided, the function will use all unique keys found in the objects.

    Returns (string | T | E)[][]

    A 2D array (table) where each row represents an object and each column represents a property of the object.

    Example

    arrObjectsToTable(
    [
    { a: 1, b: 2 },
    { a: 3, b: 4, c: 5 },
    ],
    { emptyCell:1 },
    ) //=> [ [ 'a', 'b', 'c' ], [ 1, 2,1 ], [ 3, 4, 5 ] ]

Generated using TypeDoc