Object.fromEntries in JavaScript

Level 3108 keystrokes

Object.fromEntries() transforms a list of key-value pairs into an object.

JavaScript code

// Create an array of key-value pair arrays
// Each inner array has [key, value] format
1const entries = [["name", "Alice"], ["age", 25]];
// Object.fromEntries() converts the entries to an object
// This is the reverse of Object.entries()
2const obj = Object.fromEntries(entries);
// Print the resulting object { name: "Alice", age: 25 }
3console.log(obj);

Output

{ name: 'Alice', age: 25 }
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this JavaScript code and how often they appear.

  • "× 6
  • ,× 3
  • ;× 3
  • [× 3
  • ]× 3
  • .× 2
  • (× 2
  • )× 2
  • =× 2

More JavaScript examples at level 3

← JavaScript typing practice