repl.txt (2005B)
1 2 {{alias}}( obj, path, value[, options] ) 3 Sets a nested property value. 4 5 Parameters 6 ---------- 7 obj: ObjectLike 8 Input object. 9 10 path: string|Array 11 Key path. 12 13 value: any 14 Value to set. 15 16 options: Object (optional) 17 Options. 18 19 options.create: boolean (optional) 20 Boolean indicating whether to create a path if the key path does not 21 already exist. Default: false. 22 23 options.sep: string (optional) 24 Key path separator. Default: '.'. 25 26 Returns 27 ------- 28 bool: boolean 29 Boolean indicating if the property was successfully set. 30 31 Examples 32 -------- 33 > var obj = { 'a': { 'b': { 'c': 'd' } } }; 34 > var bool = {{alias}}( obj, 'a.b.c', 'beep' ) 35 true 36 37 // Specify an alternative separator via the sep option: 38 > obj = { 'a': { 'b': { 'c': 'd' } } }; 39 > bool = {{alias}}( obj, 'a/b/c', 'beep', { 'sep': '/' } ); 40 > obj 41 { 'a': { 'b': { 'c': 'beep' } } } 42 43 // To create a key path which does not exist, set the create option to true: 44 > bool = {{alias}}( obj, 'a.e.c', 'boop', { 'create': true } ); 45 > obj 46 { 'a': { 'b': { 'c': 'beep' }, 'e': { 'c': 'boop' } } } 47 48 49 {{alias}}.factory( path[, options] ) 50 Creates a reusable deep set function. 51 52 Parameters 53 ---------- 54 path: string|Array 55 Key path. 56 57 options: Object (optional) 58 Options. 59 60 options.create: boolean (optional) 61 Boolean indicating whether to create a path if the key path does not 62 already exist. Default: false. 63 64 options.sep: string (optional) 65 Key path separator. Default: '.'. 66 67 Returns 68 ------- 69 out: Function 70 Deep get function. 71 72 Examples 73 -------- 74 > var dset = {{alias}}.factory( 'a/b/c', { 75 ... 'create': true, 76 ... 'sep': '/' 77 ... }); 78 > var obj = { 'a': { 'b': { 'c': 'd' } } }; 79 > var bool = dset( obj, 'beep' ) 80 true 81 > obj 82 { 'a': { 'b': { 'c': 'beep' } } } 83 84 See Also 85 -------- 86