我使用服务将数组元素添加到数组中,该服务成功添加了元素。我可以看到使用console.log登录的数据无法访问数组的元素
但我无法访问该元素。
this.routingService.getNode(startNode).subscribe(node => {
node.forEach(node => {
this.openSet.push(new MapNode(node.id, node.lon, node.lat, this.routingService.getNodeNeighbours(node.id)));
});
});
console.log(this.openSet); // this prints out the below screenshot
然而,当我使用类似:
console.log(this.openSet[0]);
我得到的 '未定义' 输出。我不确定我现在是否真的很厚我现在在访问它或不...
任何想法?
你可以发布你所看到的,当你做的console.log(JSON.stringify(this.openSet)); – Sajeetharan
请将javascript标签添加到问题 – baao
[如何从异步调用返回响应?](https://stackoverflow.com/questions/14220321/how-to-return-the-response-from-一个异步调用) – baao