The mapValues
function from the Lodash library allows you to map over the values of an object and change them according to a function you define. The resulting object will have the same keys as the original object, but with the mapped values. Here's an example:
index.tsx176 chars12 lines
In this example, we require Lodash and define an object with three keys and values. We then use mapValues
to map over the values of this object and multiply each value by 2. The resulting object is logged to the console.
Note that mapValues
works on objects, not on arrays. If you want to map over the elements of an array, you can use the map
function instead.
index.tsx117 chars6 lines
This is a regular map
function on an array. The resulting array contains the mapped values of the original array.
gistlibby LogSnag