NewDash

    Function set

    • 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.

      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.

      5.3.0

      [[has]],[[hasIn]],[[get]],[[unset]]

      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
    • 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.

      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.

      5.3.0

      [[has]],[[hasIn]],[[get]],[[unset]]

      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
    MMNEPVFCICPMFPCPTTAAATR