Prepare repository for merge
This commit is contained in:
22
javascript/snippets/map-to-object.md
Normal file
22
javascript/snippets/map-to-object.md
Normal file
@ -0,0 +1,22 @@
|
||||
---
|
||||
title: Convert Map to object
|
||||
type: snippet
|
||||
shortTitle: Map to object
|
||||
tags: [object]
|
||||
author: chalarangelo
|
||||
cover: succulent-1
|
||||
dateModified: 2022-06-16T05:00:00-04:00
|
||||
---
|
||||
|
||||
Converts a `Map` to an object.
|
||||
|
||||
- Use `Map.prototype.entries()` to convert the `Map` to an array of key-value pairs.
|
||||
- Use `Object.fromEntries()` to convert the array to an object.
|
||||
|
||||
```js
|
||||
const mapToObject = map => Object.fromEntries(map.entries());
|
||||
```
|
||||
|
||||
```js
|
||||
mapToObject(new Map([['a', 1], ['b', 2]])); // {a: 1, b: 2}
|
||||
```
|
||||
Reference in New Issue
Block a user