@@ -40,7 +40,10 @@ Sets a nested property value.
40
40
var obj = { ' a' : { ' b' : { ' c' : ' d' } } };
41
41
42
42
var bool = deepSet ( obj, ' a.b.c' , ' beep' );
43
- // obj => { 'a': { 'b': { 'c': 'beep' } } }
43
+ // returns true
44
+
45
+ console .log ( obj );
46
+ // => { 'a': { 'b': { 'c': 'beep' } } }
44
47
```
45
48
46
49
If the function is able to deep set a nested property, the function returns ` true ` ; otherwise, the function returns ` false ` .
@@ -74,7 +77,10 @@ var arr = [
74
77
];
75
78
76
79
var bool = deepSet ( arr, ' 1.a.0.x' , 25 );
77
- /* arr =>
80
+ // returns true
81
+
82
+ console .log ( arr );
83
+ /* =>
78
84
[
79
85
{ 'a': [ { 'x': 5 } ] },
80
86
{ 'a': [ { 'x': 25 } ] }
@@ -89,8 +95,8 @@ The key `path` may be specified as either a delimited `string` or a key `array`.
89
95
``` javascript
90
96
var obj = { ' a' : { ' b' : { ' c' : ' d' } } };
91
97
92
- var bool = deepSet ( obj, [ ' a' , ' b' , ' c' ], ' beep' );
93
- // obj => { 'a': { 'b': { 'c': 'beep' } } }
98
+ var bool = deepSet ( obj, [ ' a' , ' b' , ' c' ], ' beep' ); // obj => { 'a': { 'b': { 'c': 'beep' } } }
99
+ // returns true
94
100
```
95
101
96
102
If ` value ` is a ` function ` , the argument is treated as a ` callback ` and should return a value to set.
@@ -108,8 +114,8 @@ function set( val ) {
108
114
}
109
115
var obj = { ' a' : { ' b' : { ' c' : ' d' } } };
110
116
111
- var bool = deepSet ( obj, ' a.b.c' , set );
112
- // obj => { 'a': { 'b': { 'c': 'ddddd' } } }
117
+ var bool = deepSet ( obj, ' a.b.c' , set ); // obj => { 'a': { 'b': { 'c': 'ddddd' } } }
118
+ // returns true
113
119
```
114
120
115
121
The function accepts the following ` options ` :
@@ -127,7 +133,10 @@ var obj = { 'a': { 'b': { 'c': 'd' } } };
127
133
var bool = deepSet ( obj, ' a/b/c' , ' beep' , {
128
134
' sep' : ' /'
129
135
});
130
- // obj => { 'a': { 'b': { 'c': 'beep' } } }
136
+ // returns true
137
+
138
+ console .log ( obj );
139
+ // => { 'a': { 'b': { 'c': 'beep' } } }
131
140
```
132
141
133
142
To create a key path which does not already exist, set the ` create ` option to ` true ` .
@@ -140,7 +149,10 @@ var obj = { 'a': { 'b': { 'c': 'd' } } };
140
149
var bool = deepSet ( obj, ' a.e.c' , ' boop' , {
141
150
' create' : true
142
151
});
143
- /* obj =>
152
+ // returns true
153
+
154
+ console .log ( obj );
155
+ /* =>
144
156
{
145
157
'a': {
146
158
'b': {
@@ -177,7 +189,10 @@ var dset = deepSet.factory( 'a.b.c' );
177
189
var obj = { ' a' : { ' b' : { ' c' : ' d' } } };
178
190
179
191
var bool = dset ( obj, ' beep' );
180
- // obj => { 'a': { 'b': { 'c': 'beep' } } }
192
+ // returns true
193
+
194
+ console .log ( obj );
195
+ // => { 'a': { 'b': { 'c': 'beep' } } }
181
196
```
182
197
183
198
</section >
0 commit comments