Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

200
Views
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. But my question is how do we get the Map value if we derived it from asynchronous function like in this code below:

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);
}
I want to use the value from this function using this code:

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"];
Please, help me out. Any tips and trick will be great. Thank you very much for spending time to read this post.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Both are correct in Javascript,

  • 1- Dot property accessor: object. property.
  • 2- Square brackets property access: object['property']
  • 3- Object destructuring: const { property } = object.

This style is named Object Dot Notation access

const code = response.code;
const token = response.token;

and this one is Object Bracket notation access

const code = response["code"];
const token = response["token"];

Read more here

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!