_.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>

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-18
猜你喜欢
  • 2022-12-23
  • 2021-05-17
  • 2022-12-23
  • 2022-01-18
  • 2022-12-23
  • 2022-12-23
  • 2022-01-11
相关资源
相似解决方案