Skip to content

Function: repeat() ​

ts
function repeat<T>(value, count): T[];

Creates an array with a single value repeated n times. 创建一个包含重复值的数组。

Type Parameters ​

Type Parameter
T

Parameters ​

ParameterTypeDescription
valueTThe value to repeat / 要重复的值
countnumberThe number of times to repeat / 重复次数

Returns ​

T[]

An array with repeated values / 包含重复值的数组

Example ​

typescript
repeat(0, 5) // => [0, 0, 0, 0, 0]
repeat('hello', 3) // => ['hello', 'hello', 'hello']
repeat(true, 2) // => [true, true]

Since ​

1.0.0

Released under the MIT License.