title: How can I deep copy an objects that contains nested objects and arrays?
body: <p>I'm trying to implement a method to copy dungeons in a game managment app.</p>
  <p>Here is an example of a Dungeon to be copied:</p>
  <pre><code>attributes: { isReady: true, isMainQuest: true, color: &quot;red&quot;, partyMax: 8 }
  id: 59272
  gamerMax: 12
  gameId: 3
  advLeveling: true
  mainObjects: [0: &quot;Treasure&quot; 1: &quot;BossKill&quot;]
  stats: { monsterCount: 25, treasureCount: 50, bossCount: 15 }
  </code></pre>
  <p>After reading a lot of posts about <code>Object.keys</code>, I decided to use that to &quot;deep copy&quot; my dungeon.</p>
  <p>My latest interation simply looks like this:</p>
  <pre><code>Object.keys(obj).forEach(function (prop) {
          console.log(&quot;obj[prop]: &quot;, obj[prop]);
  }
  </code></pre>
  <p>But in all the versions I tried, including the one above, they never deep copy the nested arrays and objects like attributes, mainObjects, and stats.</p>
  <p>Is there a way to copy those as well, no matter how deep?</p>
  <p>Thanks!</p>