Underscore.js _.cycle() Method
The _.cycle() Method takes an integer value and an array which is then used to build an array containing the number of iterations through the given array, strung end-to-end.
A new array created contains the given array number of given times.
- integer: The number of times given array is iterated.
- array: The array which is iterated to make a new array
Return Value: This method returns a cycled array.
underscore.js contrib library can be installed using npm install underscore-contrib –save
Example: In this example, we will simply create a cycled array using this method.
cycled array : [ 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3 ]