A javascript library for working with objects
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'
// }]
//}