DEV Community

mktoho
mktoho

Posted on

1

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)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay