dynamicArray (source code)
- Curried: false
- Failsafe status: not failsafe
The dynamicArray
function constructs an array of a specified length using a
provided function to generate each element. The function takes the index as a
parameter and is expected to return the element corresponding to that index.
This function does not include a failsafe mechanism, so it is important to ensure that the provided function and length are valid to prevent errors.
count
: The length of the array to be generated.elementGenerator
: The function that returns the element to be generated for that index. This function will get index as a parameter.
dynamicArray(3, index => `option ${index + 1}`);
// output: ["option 1", "option 2", "option 3"]