Options
All
  • Public
  • Public/Protected
  • All
Menu

Module set

Index

References

Functions Object

References

Renames and re-exports __type

Object Functions

  • set(object: any, path: string[], value: any): any
  • set(object: any, path: string, value: any): any
  • Sets the value at path of object. If a portion of path doesn't exist, it's created. Arrays are created for missing index properties while objects are created for all other missing properties. Use setWith to customize path creation.

    Note: This method mutates object.

    since

    5.3.0

    see

    has,hasIn,get,unset

    example
    const object = { 'a': [{ 'b': { 'c': 3 } }] }

    set(object, 'a[0].b.c', 4)
    console.log(object.a[0].b.c)
    // => 4

    set(object, ['x', '0', 'y', 'z'], 5)
    console.log(object.x[0].y.z)
    // => 5

    Parameters

    • object: any

      The object to modify.

    • path: string[]

      The path of the property to set.

    • value: any

      The value to set.

    Returns any

    Returns object.

  • Parameters

    • object: any
    • path: string
    • value: any

    Returns any