Skip to content

Object.fromEntries Example

Posted on:April 29, 2021 at 12:13 PM

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))

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.