• Get/set a property of an object using dot notation

    Type Parameters

    • T

    Parameters

    • obj: any

      source object to search

    • prop: string

      property name (Dot notation & indexing allowed)

    • set: T

      Set object property to value, omit to fetch value instead

    Returns T

    property value

    // Get a value
    const name = dotNotation<string>(person, 'firstName');
    const familyCarMake = dotNotation(family, 'cars[0].make');
    // Set a value
    dotNotation(family, 'cars[0].make', 'toyota');
  • Type Parameters

    • T

    Parameters

    • obj: any
    • prop: string

    Returns T | undefined