title: Push onto array with loop in Typescript
body: <p>I have the following code, which is the answer to my earlier question: <a href="https://stackoverflow.com/questions/45741426/looping-through-2d-typescript-array-and-making-new-array-from-value-at-index/45746574?noredirect=1#comment78471841_45746574">Looping through 2d Typescript array and making new array from value at index</a> if only it worked. I thought I would repost because otherwise the orig. post would get too complicated.</p>
  
  <p>I don't understand why I can't seem to push to an array, or access the array outside the loop?</p>
  
  <pre><code>  this.days_in_month = [
      [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31], [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31], [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31], [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31], 
    ];
  
    this.month_weekdays = [];
    this.days_in_month.forEach(function each(item) {
        // console.log(item);
        item.forEach(function each(value){
          // console.log(value);
  
          let thing: number = value;
            for(var i = 0; i &lt; thing; i++) {
              let weekdays: string[] = [ 'M','T','W','T','F','S','S' ];
              let wkday: string = (weekdays[(i%7)]);
              this.month_weekdays.push(wkday);
            };
        });
    });
  </code></pre>
  
  <p>I think "this.month_weekdays.push(wkday);" should push the string wkday to the array month_weekdays, so that for every value in the array days_in_month it should loop through weekdays and assign the string at index i%7 to index i of month_weekdays</p>
  
  <p>So for the first value in days_in_month month_weekdays should look like:</p>
  
  <p>MTWTFSSMTWTFSSMTWTFSSMTWTFSSMTW</p>
  
  <p>(And because December has 31 days this should also be the final value of month_weekdays)</p>