Skip to content
This repository has been archived by the owner on Apr 1, 2023. It is now read-only.

Latest commit

 

History

History
63 lines (53 loc) · 2.1 KB

set.md

File metadata and controls

63 lines (53 loc) · 2.1 KB

Object Agent

A javascript library for working with objects

npm build coverage deps size vulnerabilities license


set(object, path, value) ⇒ Object

Sets a nested value in an object. Keys in the path that don't exist at any point in the object will be created and added to the object once.

Returns: Object - The mutated object.

Param Type Description
object Object
path String Dot delimited string
value *

Example

import { set } from 'object-agent';

const thing = {
    a: [{
        b: 'c'
    }, {
        b: 'd'
    }]
};

set(thing, 'a.1.b', 'e');
console.log(thing);
// => {
//    a: [{
//        b: 'c'
//    }, {
//        b: 'e'
//    }]
//}