The objFromEntries() method transforms a list of key-value pairs into an object. This is the reverse of objEntries().
0.12.0
An iterable object that contains key-value pairs (typically an array of [key, value] arrays)
A new object whose properties are given by the entries
// Convert an array of key-value pairs into an objectconst entries = [['name', 'John'], ['age', 30]];const obj = objFromEntries(entries);// { name: "John", age: 30 }// Convert a Map to an objectconst map = new Map([['name', 'John'], ['age', 30]]);const obj = objFromEntries(map);// { name: "John", age: 30 }// Transforming an objectconst object = { a: 1, b: 2, c: 3 };const newObject = objFromEntries( objEntries(object).map(([key, value]) => [key, value * 2]));// { a: 2, b: 4, c: 6 } Copy
// Convert an array of key-value pairs into an objectconst entries = [['name', 'John'], ['age', 30]];const obj = objFromEntries(entries);// { name: "John", age: 30 }// Convert a Map to an objectconst map = new Map([['name', 'John'], ['age', 30]]);const obj = objFromEntries(map);// { name: "John", age: 30 }// Transforming an objectconst object = { a: 1, b: 2, c: 3 };const newObject = objFromEntries( objEntries(object).map(([key, value]) => [key, value * 2]));// { a: 2, b: 4, c: 6 }
Creates an object from an iterable of key-value pairs
The type of values in the resulting object
An iterable of key-value pairs
An object created from the key-value pairs
The objFromEntries() method transforms a list of key-value pairs into an object. This is the reverse of objEntries().
Since
0.12.0
Param: entries
An iterable object that contains key-value pairs (typically an array of [key, value] arrays)
Returns
A new object whose properties are given by the entries
Example