Object in JavaScript

Published on 3 Feb, 2021

Object Static Methods

Static methods are used directly from the Object constructor function. They are properties of Object.

fromEntries() ES10

fromEntries() is used to convert an iterable to an object. Examples of iterable are Arrays, Maps and objects that implements the iterable protocol.

Object from Array

The elements of the array should be in [key, value] format.

const arr = [
  ["name", "Backbencher"],
  ["age", 26],
];

const obj = Object.fromEntries(arr);

console.log(obj);

And the output is:

{
  age: 26,
  name: "Backbencher"
}

Object from Map

The elements of the passed array should be in [key, value] format.

const arr = new Map([
  ["name", "Backbencher"],
  ["age", 26],
]);

const obj = Object.fromEntries(arr);

console.log(obj);

And the output is:

{
  age: 26,
  name: "Backbencher"
}