javascript - 访问从异步函数返回的对象中的属性 - NodeJS
问题描述
我试图从 Google Geocoding API 中找到坐标(纬度和经度),但我不知道如何访问我返回的对象中的属性。这是代码:
const geoCoor = async function () {
const url = `https://maps.googleapis.com/maps/api/geocode/json?address=${address}&key=${API_KEY}`;
const response = await request.get(url);
return response
};
(async function(){
let data = await geoCoor();
console.log(data.results[0]);
})();
I've tried wrapping it in an IIFE, but when I try to access the array, I am still getting the "undefined" error message.
解决方案
推荐阅读
- redirect - IIS 重写/重定向规则查询
- python - 有没有办法在 Maya 的参考编辑器中自动更改未解析的名称?
- javascript - 如何在带有本机反应的平面列表中显示具有动态名称的数组数据列表?
- python - 如何将 Python3.4 与 Anaconda 一起使用?
- javascript - 将 javascript 对象从一种形式转换为另一种形式
- reactjs - 错误:无效的挂钩调用。Hooks 只能在函数组件的主体内部调用
- amazon-web-services - 为什么 AWS EC2 实例身份验证一直停止工作(可能是会话)?
- reactjs - Redux vs Hooks/Context API vs ApolloClient
- matrix - 变换后如何计算屏幕坐标?
- visual-studio-code - 在哪里定义一个共享的problemMatcher来检查终端?