多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
## setWith + [link](./setWith "Link to this entry.") + [source](https://github.com/lodash/lodash/blob/4.5.0正式版/lodash.src.js#L11700 "View in source.") + [npm](https://www.npmjs.com/package/lodash.setwith "See the npm package.") ``` _.setWith(object, path, value, [customizer]) ``` 这个方法类似 `_.set`。 除了它接受一个 `customizer` 决定如何设置对象路径的值。 如果 `customizer` 返回 `undefined` 将会有它的处理方法代替。 `customizer` 会传入3个参数:(nsValue, key, nsObject) **注意:** 这个方法会改变源对象 ### 参数 1. object (Object) 要修改的对象 2. path (Array|string) 要设置的对象路径 3. value (\*) 要设置的值 4. [customizer] (Function) 这个函数决定如何分配值 ### 返回值 (Object) 返回对象 ### 示例 ``` _.setWith({ '0': { 'length': 2 } }, '[0][1][2]', 3, Object); // => { '0': { '1': { '2': 3 }, 'length': 2 } } ```