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)

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

👋 Kindness is contagious

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

Okay