Javatpoint Logo
Javatpoint Logo

The Object.fromEntries() Method in JavaScript

The Object.fromEntries() method converts a list of key-value pairs into an object. It is a standard built-in JavaScript object's method to operate an array. This function creates a brand-new object whose properties are determined by the iterable's entries.

Syntax:

The following syntax is used in the JavaScript tag.

Explanation

  • The only parameter this function allows is an iterable, such as an array, map, or object that follows the iterable protocol.
  • A new object with properties provided by the iterable's entries is returned by the Object.fromEntries() method.
  • The iterable provides an iterator object that generates key-value pairs using the Object.fromEntries(). It uses the key as the object's property key and the value as its corresponding value.
  • The Object.fromEntries() function executes Object.entries in reverse().
  • Return value: The iterable's entries serve as the basis for a new object that this function always returns.

Examples

The examples display the Object.fromEntries() method with different types of input values. We can see the array, map, and other data convert into the object using the method.

Example 1: the following example shows the basic Object.fromEntries() method for the array values. We use a basic array with the integer key and string values.

Output

The output shows in the console tab with the array data.

The Object.fromEntries() Method in JavaScript

Example 2: the following example shows the basic Object.fromEntries() method for the array values. We use a basic array with the string key and various values in the map variable.

Output

The output shows in the console tab with the array data.

The Object.fromEntries() Method in JavaScript

Example 3: the following example shows the basic Object.fromEntries() method for the map values. We use a basic array with the integer key and string values in the map variable.

Output

The output shows in the console tab with the map data.

The Object.fromEntries() Method in JavaScript

Example 4: the following example shows the basic Object.fromEntries() method for the map values.

Output

The output shows in the console tab with the map data.

The Object.fromEntries() Method in JavaScript

Example 5: the following example shows the basic Object.fromEntries() method for the URL parameters.

Output

The output shows in the console tab with the url Parameters.

The Object.fromEntries() Method in JavaScript

Conclusion

The Object.fromEntries() method operates multiple data using the iteration function. It is working for the revrse of the object entries method.







Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA