title: ERROR TypeError: Cannot read property 'forEach' of undefined in setInterval function
body: <p>So in the below code I'm pushing an object in the messages array after I receive  it from a websocket. After this I would like to call setInterval and add a minute to the minutesAgo property of the objects inside the messages array every 60 seconds. </p>
  
  <p>Unfortunately I get an error <code>ERROR TypeError: Cannot read property 'forEach' of undefined</code> inside the <code>getMinutesAgo()</code> function. I pushed the object into the messages array earlier, so I don't understand why <code>this.messages</code> is undefined. Does someone know why? </p>
  
  <pre><code>export class MovieChatComponent implements OnInit{
  
      fullName;
      title = 'Websocket Demo';
      url;
      ws;
      messages = [];
      movieChatElem;
  
      constructor(private movieChatService: MovieChatService){
  
      }
  
      ngOnInit(){
          this.fullName = localStorage.getItem('fullName');
          this.url = 'ws://localhost:3185';
          this.movieChatService.createObservableSocket(this.url)
              .subscribe(obj =&gt; {
                  console.log(obj);
                  this.messages.push(obj);
                  console.log(this.messages);
                  this.movieChatElem.scrollTop = this.movieChatElem.scrollHeight - this.movieChatElem.clientHeight;
                  this.startTimeCalculations()
                  },
                  err =&gt; console.log(err),
                  () =&gt; console.log('The observable stream, is complete'));
      }
  
      startTimeCalculations(){
          setInterval(this.getMinutesAgo,60000);
      }
  
      getMinutesAgo (){
          console.log('entered');
          console.log(this.messages);
          this.messages.forEach(function (msg) {
              msg.minutesAgo++;
              console.log('done');
              console.log(msg.minutesAgo);
          })
      }
  }
  </code></pre>