_.flatten(array)
向上一级展平数组嵌套
<!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta http-equiv="X-UA-Compatible" content="ie=edge" /> <title>展平数组</title> </head> <body> <script src="https://cdn.bootcss.com/lodash.js/4.17.10/lodash.min.js"></script> <script type="text/javascript"> var arr = _.flatten([1, [2, [3, [4]], 5]]); console.log(arr); //[1, 2, [3, [4]], 5] var arr1 = _.flattenDeep([1, [2, [3, [4]], 5]]); console.log(arr1); //[1, 2, 3, 4, 5] </script> </body> </html>