You can use the apply
function from lodash to apply a function to elements of an array. The apply
function takes three arguments: an array of values to apply the function to, the function to apply, and any additional arguments to pass to the function. Here's an example:
index.tsx362 chars16 lines
In this example, we imported the apply
function from lodash using the require
function. We then defined a function called timesTwo
that doubles the input number. Next, we defined an array of numbers to apply the function to. Finally, we used the apply
function to apply the timesTwo
function to each element of the numbers
array, resulting in a new array with the results.
gistlibby LogSnag