DEV Community

mktoho
mktoho

Posted on

mapping javascript object values

A method that maps only the values of a javascript object, which is a set of key/value pairs, like the map function of an array.

const entriesMap = (object, callbackfn) => {
  const entries = Object.entries(object).map(e => callbackfn(e))
  return Object.fromEntries(entries)
}

const valuesMap = (object, callbackfn) =>
  entriesMap(object, ([k, v]) => [k, callbackfn(v)])

export { entriesMap, valuesMap }
Enter fullscreen mode Exit fullscreen mode

Top comments (0)