> For the complete documentation index, see [llms.txt](https://martins-victor.gitbook.io/1loc-lib/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://martins-victor.gitbook.io/1loc-lib/one-liners/clonearray.md).

# cloneArray

Creates a clone of an array.

This function receives an array and returns a clone of that array.&#x20;

Why this is useful? Well, Javascript copies by reference. So if you "copy" an array like this;

```javascript
let a = [1, 2, 3]
let b = a
```

Your variable `b` would only be referencing the variable `a`. This basically means if a is updated, `b` gets updated too.&#x20;

```javascript
a.push(4)

console.log(b) // [1, 2, 3, 4]
```

This function copies by value and not by reference.&#x20;

```javascript
import { cloneArray } from '1loc'

let a = [1, 2, 3]
let b = cloneArray(a) // [1, 2, 3]

a.push(4)

console.log(b) // [1, 2, 3] (remains unchanged)
```
