Creates an infinite generator that repeatedly cycles through the values of an iterable. If the input iterable is empty, returns an empty generator.
Type of elements in the iterable
The source iterable to cycle through
An infinite generator that cycles through the input values
Values from the source iterable, repeatedly cycling through them indefinitely
// Create a cycling generator of numbersconst cycled = cycle([1, 2, 3])const first6Values = []for (let i = 0; i < 6; i++) { first6Values.push(cycled.next().value)}// Result: [1, 2, 3, 1, 2, 3] Copy
// Create a cycling generator of numbersconst cycled = cycle([1, 2, 3])const first6Values = []for (let i = 0; i < 6; i++) { first6Values.push(cycled.next().value)}// Result: [1, 2, 3, 1, 2, 3]
// Create a cycling generator from a stringconst letters = cycle("ABC")const first5Values = []for (let i = 0; i < 5; i++) { first5Values.push(letters.next().value)}// Result: ['A', 'B', 'C', 'A', 'B'] Copy
// Create a cycling generator from a stringconst letters = cycle("ABC")const first5Values = []for (let i = 0; i < 5; i++) { first5Values.push(letters.next().value)}// Result: ['A', 'B', 'C', 'A', 'B']
Creates an infinite generator that repeatedly cycles through the values of an iterable. If the input iterable is empty, returns an empty generator.