TypeScript loop push

90 Views Asked by At

In loop session: I can get data out but outside the loop I can't "log" it.

getAbouts(){
  this.getInfos().subscribe(data => {
    console.log(data);
    this.data = data;

    for (var k of this.data){
      // console.log("data is components: " + k.ten_demuc);
      this.getData.push(k.ten_demuc);
      //console.log(this.getData);
    }
  })
}
1

There are 1 best solutions below

1
On

Instead of var you can use let in the for loop.

for (let k of this.data){

}