title: ERROR TypeError: .forEach is not a function
body: <p>In my Angular program, I need to create a deep copy of my object so that I'll be able to compare the changes. Here is what I tried and I get an error in my console that says <code>ERROR TypeError: .forEach is not a function</code>. How do I fix this?</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
  
  import { PTOData } from './pto-data';
  import { PTODataService } from './pto-data.service';
  import { EmpInfo } from './emp-info';
  import { EmpInfoService } from './emp-info.service';
  
  @Component({
      selector: '[pto-row-edit]',
      templateUrl: `./row-edit.component.html`,
      styleUrls: ['./row-edit.component.css']
  })
  
  export class RowEditComponent implements OnInit {
  
      // Inputs &amp; Outputs to/from grid component
      @Input() pto: PTOData[];
      @Input() rowSelected: number;
  
      @Output() onDelete = new EventEmitter&lt;number&gt;();
      @Output() onSave = new EventEmitter&lt;number&gt;();
  
      opto: PTOData[];
  
      private initialized: boolean = false;
  
      ngOnInit(): void {
          this.opto = [];
          this.pto.forEach(x =&gt; this.opto.push(x))
          console.log(this.opto);
      }
  
      constructor(
          private ptodataService: PTODataService,
          private empInfoService: EmpInfoService) { }
  
      resetRow(pto: PTOData): void {
          console.log(this.pto);
          console.log(this.opto);
          this.rowSelected = null;
          this.onSave.emit(this.rowSelected);
      }
  
  }</code></pre>
  </div>
  </div>
  </p>