AI写作智能体 自主规划任务,支持联网查询和网页读取,多模态高效创作各类分析报告、商业计划、营销方案、教学内容等。 广告
## flatMap + [link](./flatMap "Link to this entry.") + [source](https://github.com/lodash/lodash/blob/4.5.0正式版/lodash.src.js#L7672 "View in source.") + [npm](https://www.npmjs.com/package/lodash.flatmap "See the npm package.") ``` _.flatMap(collection, [iteratee=_.identity]) ``` 创建一个扁平化的数组,每一个值会传入 iteratee 处理,处理结果会与值合并。 iteratee 会传入3个参数:(value, index|key, array)。 ### 参数 1. collection (Array|Object) 需要遍历的数组 2. [iteratee=_.identity] (Function|Object|string) 这个函数会在每一次迭代调用 ### 返回值 (Array) 返回新数组 ### 示例 ``` function duplicate(n) { return [n, n]; } _.flatMap([1, 2], duplicate); // => [1, 1, 2, 2] ```