Lodash - flattenDepth 方法



語法

_.flattenDepth(array, [depth=1])

向下的重複展平陣列,次數為 depth。

引數

  • array (陣列) − 要展平的陣列。

  • [depth=1] (數字) − 最大遞迴深度。

輸出

  • (陣列) − 返回新的展平陣列。

示例

var _ = require('lodash');
var list = [1, [2], [4], 5, [[6]]];
var result = _.flattenDepth(list,2)

console.log(result);

將以上程式儲存在 tester.js 中。執行以下命令來執行此程式。

命令

\>node tester.js

輸出

[ 1, 2, 4, 5, 6 ]
lodash_array.htm
廣告
© . All rights reserved.