title: Create clone of an object in JavaScript
body: <p>In JavaScript,</p>
  
  <pre><code>var arr = [1, 2, 3, 4, 5];
  var arr2 = arr.slice();
  </code></pre>
  
  <p><code>arr2</code> will not change if <code>arr</code> values are changed. That is, <code>arr[0] = 0;</code>, still <code>arr2[0] == 1; // true</code>.</p>
  
  <p>Consider this:</p>
  
  <pre><code>var obj = {name: 'John', company: 'XYZ'};
  var obj2 = obj; // Creates a duplicate of obj
  </code></pre>
  
  <p>But <code>obj.name = 'Dave'</code>, makes <code>obj2.name = 'Dave'</code> as well.</p>
  
  <p>How can we do a <code>slice()</code> operation for objects?</p>