---
title: "Discussion on \"Copying JavaScript object and arrays\" | Hashnode"
description: "Discussion on \"Copying JavaScript object and arrays\". I recently learned this method:\nCopying a JavaScript Object\nconst source = { a: 1, b: 2 };\nconst copy = Object.assign({}, source);\nCopying a JavaScript Array\nconst arr = [0,2,3,4,5];\nconst arrCopy = arr.slice(0);\nThese two functions come handy when y..."
url: "https://hashnode.com/posts/copying-javascript-object-and-arrays/5f05e3d931045715ed6deda2"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Copying JavaScript object and arrays](https://rmoran86.hashnode.dev/copying-javascript-object-and-arrays?utm_source=hashnode&utm_medium=feed)

I recently learned this method: Copying a JavaScript Object const source = { a: 1, b: 2 }; const copy = Object.assign({}, source); Copying a JavaScript Array const arr = \[0,2,3,4,5\]; const arrCopy = arr.slice(0); These two functions come handy when y...

Jul 8, 2020 · 1 min read · rmoran86.hashnode.dev  
Read the article

-   [#2articles1week](https://hashnode.com/tag/2articles1week)
-   [#javascript](https://hashnode.com/tag/javascript)

## Written by

[Robert Moran](https://hashnode.com/@rmoran86)

@rmoran86 · Las Vegas

  
[View profile](https://hashnode.com/@rmoran86)

Software Engineer with passion for Web

Software Engineer!

## Responses 1

Markdown supported · ⌘↵ to post

[Chris Bongers](https://hashnode.com/@dailydevtips)

[Jul 9, 2020](https://hashnode.com/posts/copying-javascript-object-and-arrays/5f05e3d931045715ed6deda2/comment/5f06d19325e7571fbcdfcef5)

You can also use the three dot method

```
const arr = [0,2,3,4,5];
const arrCopy2 = [...arr];
console.log(arrCopy2);
```
