通过获取请求的数组响应循环访问

问题描述:

我想将getLocation中获得的信息存储在位置数组中,并将该值转换为浮点数。但我不知道如何来遍历存储值通过获取请求的数组响应循环访问

this.peopleservice.getLocation(ID) 
    .subscribe(data =>{this.latcoor = data[x].lat, 
    this.lngcoor=data[x].lng 

    this.lat= parseFloat(this.latcoor); 
    this.lng= parseFloat(this.lngcoor); 

    this.location= [ 
      {latitude:this.lat, longitude:this.lng}, 
     ]; 
    });} 

使用for环象下面这样:

this.peopleservice.getLocation(ID) 
    .subscribe(data => { 
    this.location = []; 
    for (let item of data) { 
     this.location.push({latitude: parseFloat(item.lat), longitude: parseFloat(item.lng)}); 
    } 
    }); 
+0

正是我工作,我要感谢这么多 – Nouf