• Type Parameters

    • T extends Record<string, any>

    Parameters

    • obj: T
    • nestedObjectKey: string

      key of nestable object

    • keysToFind: string[]

      array of keys to find at target path

    • targetPath: string = ''

      use this if you need to traverse a further than the target object

    Returns any[]

    {Array}

    Description

    Get values at path specified from nestable object (ex.invoice_lines) as array

    Example

    getArrayOfValuesFromNestedObject({nestable: {id: 1}}, 'nestable', ['id']);
    // return [{ id : 1 }]

    getArrayOfValuesFromNestedObject({nestable: {target: {id : 2}}}, 'nestable', ['id'], 'target');
    // return [{ id : 2 }]

    getArrayOfValuesFromNestedObject({nestable: {target: {id : 2}}}, 'nestable', ['id'], 'target');
    // return [{ id : 2 }]

    getArrayOfValuesFromNestedObject({id: 1, nestable:{id: 2, nestable:{id: 3}}]}, 'nestable', ['id']);
    // return [{ id : 2 }, { id : 3 }]

    getArrayOfValuesFromNestedObject(
    {
    nestable: [
    {id: 1, nestable: [{id: 11}]},
    {id: 2, nestable: [{id: 11}, {id: 21}, {id: 22}]},
    {id: 3},
    {id: 4, nestable: [{id: 41, nestable: [{id: 441}]}]},
    ]
    },
    'nestable',
    ['id']
    );
    // return [{ id : 2 }, { id : 11 }, { id : 2 }, { id : 11 }, { id : 21 }, { id : 22 }, { id : 3 }, { id : 4 }, { id : 41 }, { id : 441 }]

Generated using TypeDoc