[英]How can I access return value of Map from function in Node.js for Cloud Function?
I had read this post How to return values in javascript .我读过这篇文章How to return values in javascript 。 But my question is how do we get the Map value if we derived it from asynchronous function like in this code below:
但我的问题是,如果我们从异步 function 派生它,我们如何获得 Map 值,如下面的代码所示:
async function exampleToken(profile) { let response; const tkAdmin = { admin: true, }; const tkInvestors = { investor: true, }; if (profile == 1) { response = { "token": tkAdmin, "code": 1, }; } else if (profile == 2) { response = { "token": tkInvestors, "code": 2, }; } return Promise.resolve(response); }
const response = await exampleToken(profile); // Is this correct: const code = response.code; const token = response.token; // or const code = response["code"]; const token = response["token"];
Both are correct in Javascript, Javascript都正确,
This style is named Object Dot Notation access这种样式命名为 Object Dot Notation access
const code = response.code;
const token = response.token;
and this one is Object Bracket notation access这个是 Object 括号表示法访问
const code = response["code"];
const token = response["token"];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.