Repeats the sequence the specified number of times, or indefinitely when no count is provided.
Type of elements within the source iterable.
source
The source iterable.
Optional
Optional number of times to repeat the sequence. When omitted, the sequence repeats without end.
A sequence that yields the original elements cyclically.
Thrown when the sequence is empty.
When count is undefined, consume the result with care because it represents an infinite sequence.
count
undefined
const numbers = [1, 2, 3];const cycled = cycle(numbers, 2).toArray();console.log(cycled); // [1, 2, 3, 1, 2, 3] Copy
const numbers = [1, 2, 3];const cycled = cycle(numbers, 2).toArray();console.log(cycled); // [1, 2, 3, 1, 2, 3]
Repeats the sequence the specified number of times, or indefinitely when no count is provided.