Files
30-seconds-of-code/snippets/shallowClone.md
Angelos Chalaris 611729214a Snippet format update
To match the starter (for the migration)
2019-08-13 10:29:12 +03:00

17 lines
322 B
Markdown

---
title: shallowClone
tags: object,beginner
---
Creates a shallow clone of an object.
Use `Object.assign()` and an empty object (`{}`) to create a shallow clone of the original.
```js
const shallowClone = obj => Object.assign({}, obj);
```
```js
const a = { x: true, y: 1 };
const b = shallowClone(a); // a !== b
```