# Shallow copy an object

Copy own enumerable properties into a new object.

Canonical: https://1loc.dev/object/shallow-copy-an-object/
Version: 1.0.0
Runtime: JavaScript · Node.js 22 / modern browsers
Verification: Local fixtures; no external services
Updated: 2026-10-28

## Implementation

```javascript
function shallowCopy(object) { return { ...object }; }
```

## Input

```json
{
  "to": "ana@example.com",
  "data": {
    "name": "Ana"
  }
}
```

## Expected output

```json
{
  "to": "ana@example.com",
  "data": {
    "name": "Ana"
  }
}
```

## Edge case

Input:
```json
{}
```
Output:
```json
{}
```

## Limits

- Nested objects are shared, not copied. Use structuredClone for a deep copy.
- The original second variant, obj => {...obj}, is a block, not an object literal; it needs parentheses.

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/shallow-copy-an-object.mdx
Author: Nguyen Huu Phuoc and original contributors
Contributors: Namysh
Source commit: 14b481cf60dff1620ab1bb99a43b1f68068cdd9b
Copyright (c) 2020 phuoc-ng
License: MIT — https://1loc.dev/licenses/
Maintainer: Oveyon
Modifications: Uses object spread; the original arrow variant obj => {...obj} was a syntax error. Original MDX retained as inert source evidence.
