# Create an object from pairs of key and value

Turn [key, value] pairs into a plain object with Object.fromEntries.

Canonical: https://1loc.dev/object/create-an-object-from-the-pairs-of-key-and-value/
Version: 1.0.0
Runtime: JavaScript · Node.js 22 / modern browsers
Verification: Local fixtures; no external services
Updated: 2026-10-28

## Implementation

```javascript
function toObject(pairs) { return Object.fromEntries(pairs); }
```

## Input

```json
[
  [
    "from",
    "orders@your-verified-domain.example"
  ],
  [
    "to",
    "ana@example.com"
  ],
  [
    "subject",
    "Order 8812 confirmed"
  ]
]
```

## Expected output

```json
{
  "from": "orders@your-verified-domain.example",
  "to": "ana@example.com",
  "subject": "Order 8812 confirmed"
}
```

## Edge case

Input:
```json
[
  [
    "status",
    "deferred"
  ],
  [
    "status",
    "delivered"
  ]
]
```
Output:
```json
{
  "status": "delivered"
}
```

## Limits

- When a key repeats, the later pair wins, as the edge case shows.
- Keys become strings. A "__proto__" key becomes an ordinary own property, unlike assignment.

The lab validates types and size before calling this function. Add equivalent validation at your own trust boundary.

## Source and license

Original: https://github.com/phuocng/1loc/blob/14b481cf60dff1620ab1bb99a43b1f68068cdd9b/contents/create-an-object-from-the-pairs-of-key-and-value.mdx
Author: Nguyen Huu Phuoc and original contributors
Contributors: robinpokorny
Source commit: 14b481cf60dff1620ab1bb99a43b1f68068cdd9b
Copyright (c) 2020 phuoc-ng
License: MIT — https://1loc.dev/licenses/
Maintainer: Oveyon
Modifications: Curated Object.fromEntries variant; pair validation, repeated-key edge case and prototype-key note. Original MDX retained as inert source evidence.
