Lodash - times 方法



語法

_.times(n, [iteratee=_.identity])

呼叫 iteratee n 次,返回每次呼叫的結果陣列。iteratee 被一個引數呼叫;(index)。

引數

  • n (數字) − 多次呼叫 iteratee 的次數。

  • [iteratee=_.identity] (函式) − 每次迭代呼叫的函式。

輸出

  • (陣列) − 返回結果陣列。

示例

var _ = require('lodash');

console.log(_.times(3, String));
console.log(_.times(4, _.constant(0)));

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

命令

\>node tester.js

輸出

[ '0', '1', '2' ]
[ 0, 0, 0, 0 ]
lodash_util.htm
廣告
© . All rights reserved.