阅读(3747) (0)

Lodash _.times

2021-09-23 16:55:06 更新

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

调用 iteratee n 次,每次调用返回的结果存入到数组中。 iteratee 调用入1个参数: (index)。

添加版本

0.1.0

参数

  1. n (number): 调用 iteratee 的次数。
  2. [iteratee=_.identity] (Function): 每次迭代调用的函数。

返回

(Array): 返回调用结果的数组。

例子

_.times(3, String);
// => ['0', '1', '2']  
_.times(4, _.constant(0));
// => [0, 0, 0, 0]