DEV Community

Typing Turtle
Typing Turtle

Posted on

2

Object.fromEntries example

Wanted to share a quick code snippet I ran into:

function without(object, keys) {
  return Object.fromEntries(
    Object.entries(object).filter(([key]) => !keys.includes(key))
  );
}
Enter fullscreen mode Exit fullscreen mode

Object.fromEntries (MDN) as you'd expect creates an object from a list (any iterable not just array) of entries.

You can think of it like the inverse of Object.entries.

In this case we're using the without function to reduce an object to only the list of keys/values we want.

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

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

Okay