Skip to content

Instantly share code, notes, and snippets.

@NiallJoeMaher
Created May 14, 2019 05:09
Show Gist options
  • Save NiallJoeMaher/41b23c7cdc1b708c03a16e9a783b9693 to your computer and use it in GitHub Desktop.
Save NiallJoeMaher/41b23c7cdc1b708c03a16e9a783b9693 to your computer and use it in GitHub Desktop.
//With Object.fromEntries, you can convert from Map to Object:
const testMap = new Map([ ['hello', 'world'], ['lorem', 42] ]);
const result1 = Object.fromEntries(testMap);
console.log(result1); // { hello: "world", lorem: 42 }
//With Object.fromEntries, you can convert from Array to Object:
const testArray = [ ['first', 0], ['second', 1], ['third', 2] ];
const result2 = Object.fromEntries(testArray);
console.log(result2); // { first: 0, second: 1, third: 2 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment