title: Cloning an array in Javascript/Typescript
body: <p>I have array of two objects:</p>
  
  <pre><code>genericItems: Item[] = [];
  backupData: Item[] = [];
  </code></pre>
  
  <p>I am populating my HTML table with <code>genericItems</code>data. The table is modifiable. There is a reset button to undo all changes done with <code>backUpData</code>. This array is populated by a service:</p>
  
  <pre><code>getGenericItems(selected: Item) {
  this.itemService.getGenericItems(selected).subscribe(
    result =&gt; {
       this.genericItems = result;
    });
       this.backupData = this.genericItems.slice();
    }
  </code></pre>
  
  <p>My idea was that, the user changes will get reflected in first array and second array can be used as backup for reset operation. The issue I am facing here is when the user modifies the table (<code>genericItems[])</code> the second array <code>backupData</code> also gets modified.</p>
  
  <p>How is this happening and how to prevent this?</p>