_.flattenDeep
Recursively flattens array.
- // Underscore/Lodash
- _.flattenDeep([1, [2, [3, [4]], 5]]);
- // => [1, 2, 3, 4, 5]
- // Native
- const flattenDeep = (arr) => Array.isArray(arr)
- ? arr.reduce( (a, b) => a.concat(flattenDeep(b)) , [])
- : [arr]
- flattenDeep([1, [[2], [3, [4]], 5]])
- // => [1, 2, 3, 4, 5]
- // Native(ES2019)
- [1, [2, [3, [4]], 5]].flat(Infinity)
- // => [1, 2, 3, 4, 5]
Browser Support
46.0 ✔ | ✔ | 16.0 ✔ | ✖ | 37.0 ✔ | 7.1 ✔ |
Browser Support for Array.prototype.flat()
69 ✔ | ✖ | 62 ✔ | ✖ | 56 ✔ | 12 ✔ |
当前内容版权归 you-dont-need 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 you-dont-need .