title: Pushing data in an array with foreach in ngOnInit
body: <p>In order to fill a multiselect dropdown, I would like to request my web service, get data from it, and then create a custom array with specific objects, different from those I got from the WS. </p>
  
  <p>I would like to be able to do it in ngOnInit in order to have this multiselect dropdown already filled when the page is loaded.</p>
  
  <p>My only problem is Angular doesn't seems to want to let me push things in an array with a forEach inside ngOnInit. It doesn't give any error, but just doesn't fill my array.</p>
  
  <p>Here is some code :</p>
  
  <pre><code>fonctions: any[];
  dropdownList = [];
  
  ngOnInit() {
  
  this.serviceFct.getAll()
  .subscribe(response =&gt;  {
      this.fonctions = response as any;
  
      this.fonctions.forEach(element =&gt; {
      this.dropdownList.push({item_id: element.idFct, item_text: element.nomFct });
      }); 
  });}
  </code></pre>
  
  <p>However, if i try to fill the same array with the same foreach with a button, it just works like a charm. Why and how to fix it ?</p>
  
  <p>Edit :
  Answers there gave me the idea to try something that did work :</p>
  
  <pre><code>let dropdown = [];
  this.fonctions.forEach(element =&gt; {
    dropdown.push({item_id: element.idFct, item_text: element.nomFct });
  }); 
  this.dropdownList = dropdown;
  </code></pre>
  
  <p>Why did this work and not my first implementation ?</p>