JS: Object.fromEntries (Iterable to Object)
New in JS2019.
Object.fromEntries(iterableX)
-
Convert iterableX to data object.
Return a object with key value pairs from
Iterable Object
iterableX.
The iterableX must have pairs as element, such as nested array, or
map.
〔see the Map Object Tutorial〕
// convert nested array of tuple to object const aa = [["a", 3], ["b", 4]]; const jj = Object.fromEntries(aa); console.log(jj); // { a: 3, b: 4 }
// convert map to object const xx = new Map([["a", 3], ["b", 4]]); const jj = Object.fromEntries(xx); console.log(jj); // { a: 3, b: 4 }