A utility for setting deeply nested values of object
import set from 'set-deep';
var a = {
b: {
c: {
d: [
{},
{}
]
}
}
}
set(a, 'b.c', ['d', [1, 'e.f']])('yolo');
// The result is
// {
// b: {
// c: {
// d: [
// {},
// {
// e: {
// f: 'yolo'
// }
// }
// ]
// }
// }
// }
The parameters are quite similar to get-deep, but it returns a function that accepts one value
parameter that is the value you want to set for that path of obj
. So the full syntax will be:
set(obj, ...paths)(value)