jskatas.org Continuously Learn JavaScript. Your Way.

Object API: Object.fromEntries()

Object.fromEntries() converts key-value pairs into an object

Donate to NGO Julenka. Support Ukranians in need. Julenka is an NGO which my brother founded in 2011 to support Ukranian families and kids in need.

Object.fromEntries() converts key-value pairs (entries) into an object

  • fromEntries() method is defined on Object (not on the object literal)

GIVEN a list of entries (a key and a value) each WILL be converted into an object

  • WHERE an entry is an array with two elements
  • WHEN using arr.entries() the array-index becomes the key and values stay values
  • WHERE an entry is a Map, and key and value map naturally
  • WHERE an entry is a Set, the values are used as keys too
  • WHERE an entry is an object, the properties 0 and 1 are key and value

Links

Description of Object.fromEntries() on MDN.