One way to use the invokeMap
function from lodash is as follows:
index.tsx44 chars2 lines
The invokeMap
function applies the methodName
function to each element in collection
(an array or object), returning a new array of the results. Optional args
can be passed to the method.
Here is an example of using invokeMap
to get the uppercased version of each element of an array:
index.tsx153 chars4 lines
In this example, we pass the strings
array as the collection
parameter, and 'toUpperCase'
as the methodName
parameter. The toUpperCase
method is then applied to each element of the strings
array, and the resulting array of uppercase strings is returned and stored in uppercasedStrings
.
Note that lodash provides alternative syntaxes for invokeMap
that allow for more flexibility in the way methodName
is specified. Refer to the Lodash documentation for more information.
gistlibby LogSnag