> For the complete documentation index, see [llms.txt](https://asad-razvi.gitbook.io/javascript-cookbook/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://asad-razvi.gitbook.io/javascript-cookbook/object-recipes/second-question.md).

# How can I clone an object?

```javascript
// Define the data object you want to clone
const data = { a: 'ape', b: 'bat', c: { d: 'dog' } }
console.log('The data is ', data)

// Define a clone function based on the JSON object
const clone = (data) => JSON.parse(JSON.stringify(data))

// Use the clone function to make a deep copy of the data
const copy = clone(data))
console.log('The copy is ', copy)
```
