UNPKG

190819-utils

Version:

尚硅谷大前端自定义工具函数库

23 lines 716 B
<!DOCTYPE html> <html lang="en"> <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> <!-- 数组扁平化: 取出嵌套数组(多维)中的所有元素放到一个新数组(一维)中 如: [1, [3, [2, 4]]] ==> [1, 3, 2, 4] --> <script src="../dist/atguigu-utils.js"></script> <script> // [1] ---> [1, 3, 2, 4] // [3, [2, 4]] --> [3] --> [3, 2, 4] // [2, 4] --> [2, 4] console.log(aUtils.flatten1([1, [3, [2, 4]]])) console.log(aUtils.flatten2([1, [3, [2, 4]]])) </script> </body> </html>