The Lodash _.iterateUntil() Method takes two functions, one is used as a result generator, other function used as a stop-check and a seed value say n and returns an array of each generated result. The operation of _.iterateUntil() method is such that the result generator is passed with the seed value at the start and each subsequent result which will continue until a result fails the check function.
The generator function is feed with the starting seed value and hence array is generated until the stop-check function returns false.
_.iterateUntil(genFunc, checkFunc, seed_val)
Parameters: This method accepts three parameters as mentioned above and described below:
- genFunc: The function is used as a result generator.
- checkFunc: The function used as stop-check.
- seed_val: The value passed to the generator at starting.
Return Value: This method returns a generated array.
The lodash contrib library can be installed using npm install lodash-contrib –save
Example 1: In this example, we will generate an array using this method.
Generated Array : [ 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
Example 2: In this example, we will generate an array of 2’s table using this method by giving a seed value 0 and returning n+2 from the generating function.
Generated Array : [ 2, 4, 6, 8, 10, 12, 14, 16, 18, 20 ]