Array Scope

Can anybody please learn me why this.selectedPage[0].PageText; is working in promise but is not accessible out of it !? the array is not empty.

Runtime Error: Uncaught (in promise): TypeError: Cannot read property ‘0’ of undefined

  LoadPage(index: number){

          this.selectedPage = [];
          this.selectedPage = pagedata;
//is working here
          this.PageText = this.selectedPage[0].PageText;


//is not accessible here:
      this.PageText = this.selectedPage[0].PageText;

Your code inside the then block is executed when an async operation is completed, so when you try to access the
this.selectedPage it is still undefined. More about promises: