set

Type:Function
Status:stable
Since:1.0.0
Platform:jsnode
@blackbyte.sugar.shared.object

Set an object value using a dotted object path like “myObject.myProperty.myValue” to set his position If the path parameter is set to ’.’, it will act like an Object.assign(obj, value).

Params

  1. obj*-Object

    The object in which to set the value

  2. path*-String|String[]

    The object path where to set the value

  3. value*-Mixed

    The value to set

Return

  1. -Mixed

    Return the setted value if setted correctly, or undefined if something goes wrong…

Example

import { set } from '@blackbyte/sugar/object';
 set('myObject.cool.value', 'Hello world'); // => Hello world

Settings

  1. preferAssignfalseBoolean

    Specify if you prefer using Object.assign rather than = for objects to keep references

Todo

  • testsnormal