Prepare repository for merge

This commit is contained in:
Angelos Chalaris
2023-05-01 22:35:56 +03:00
parent fc4e61e6fa
commit b3ad01863a
578 changed files with 0 additions and 0 deletions

View File

@ -0,0 +1,21 @@
---
title: Object from pairs
type: snippet
tags: [object,array]
cover: silver-flat-screen
dateModified: 2020-10-21T21:54:53+03:00
---
Creates an object from the given key-value pairs.
- Use `Array.prototype.reduce()` to create and combine key-value pairs.
- [`Object.fromEntries()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries) provides similar functionality.
```js
const objectFromPairs = arr =>
arr.reduce((a, [key, val]) => ((a[key] = val), a), {});
```
```js
objectFromPairs([['a', 1], ['b', 2]]); // {a: 1, b: 2}
```