Function deepAccessObject

  • Access property in an object using a string path. Similar to lodash.get

    Parameters

    • access: string | string[]

      path to access

    • tar: any

      target object

    • throwOnInvalid: boolean = false

      throw error if invalid access or property is undefined. Default is false

    Returns any

    Example

    const obj = {a: {b: {c: 1}}}
    const c = deepAccessObject(['a', 'b', 'c'], obj)
    console.log(c) // 1