我正在尝试从此数组中获取lat和lng道具,但是当我将它们记录到控制台时,我得到了这个:
3ƒ(){return a} f(){return b}
steps_start_locations =[{"lat":45.2003571,"lng":12.122561899999937},
{"lat":45.200382,"lng":12.122545400000035},
{"lat":45.2046145,"lng":12.135933199999954}]
steps_start_locations.forEach( location => {
var lat = location.lat;
var lng = location.lng;
console.log(lat + ' ' + lng)
});
如何正确打印?
答案 0 :(得分:0)
正如@Dan和@guijob的评论已经提到的那样只修复forEach部分中的拼写错误并删除代码末尾的“:”。以下是代码运行版本的代码段:
step_start_locations =[{"lat":45.2003571,"lng":12.122561899999937},
{"lat":45.200382,"lng":12.122545400000035},
{"lat":45.2046145,"lng":12.135933199999954}]
step_start_locations.forEach( location => {
var lat = location.lat;
var lng = location.lng;
console.log(lat + ' ' + lng)
});
答案 1 :(得分:0)
你可以尝试这个并把你的反馈给我吗?你不应该有这个问题:
for (var i =0 ; i <steps_start_locations.lenght ;i++)
{
var lat = steps_start_locations[i].lat;
var lng = steps_start_locations[i].lng;
console.log(lat + ' ' + lng)
}