The times
method from lodash can be used to create an array of a given length with a specified value or with the results of a function.
To use it, you first need to import it from lodash:
index.tsx32 chars2 lines
Then you can use it like this:
index.tsx276 chars9 lines
The first argument to times
specifies the length of the array to create.
The second argument is optional. If it is not provided or undefined
, the array elements will be undefined
. If it is a value (not a function), each element will have that value. If it is a function, it will be called for each element with the current index as its argument and its return value will be the value of that element.
gistlibby LogSnag