Rename js snippets

This commit is contained in:
Angelos Chalaris
2023-05-19 20:23:47 +03:00
parent 82a614e42e
commit 9d032ce05e
305 changed files with 70 additions and 70 deletions

View File

@ -0,0 +1,23 @@
---
title: Convert object to Map
type: snippet
shortTitle: Object to Map
language: javascript
tags: [object]
author: chalarangelo
cover: yellow-shoes
dateModified: 2022-06-16T05:00:00-04:00
---
Converts an object to a `Map`.
- Use `Object.entries()` to convert the object to an array of key-value pairs.
- Use the `Map` constructor to convert the array to a `Map`.
```js
const objectToMap = obj => new Map(Object.entries(obj));
```
```js
objectToMap({a: 1, b: 2}); // Map {'a' => 1, 'b' => 2}
```