Function flatten

  • Flattens an array or object. Arrays will be flattened recursively up to depth times. Objects will be flattened recursively.

    Example

    flatten([1, [2, [3, [4]], 5]])
    // [1, 2, [3, [4]], 5]

    flatten({
    dates: {
    expiry_date: '30 sep 2018',
    available: '30 sep 2017',
    min_contract_period: [
    {
    id: 1,
    name: '1 month'
    }
    ]
    },
    price: {
    currency: 'RM',
    value: 1500
    }
    })
    // {
    'dates.expiry_date': '30 sep 2018',
    'dates.available': '30 sep 2017',
    'dates.min_contract_period[0].id': 1,
    'dates.min_contract_period[0].name': '1 month',
    'price.currency': 'RM',
    'price.value': 1500
    }

    Returns

    The new flattened array or object.

    See

    Array.flat()

    Type Parameters

    • T

    Parameters

    • arr: T[]

      The array or object to flatten.

    • Optional depth: number | boolean

      The max recursion depth.

    Returns T[]

  • Type Parameters

    • T

    Parameters

    • arr: Object
    • Optional depth: number | boolean

    Returns Object

Generated using TypeDoc