Snippet 1
The map() method creates a new array with the results of calling a provided function on every element in the calling array.
Snippet 2
const objectMap = (obj, fn) =>
Object.fromEntries(
Object.entries(obj).map(
([k, v], i) => [k, fn(v, k, i)]
)
)
const myObject = { a: 1, b: 2, c: 3 }
console.log(objectMap(myObject, v => 2 * v))
Copyright © Code Fetcher 2020