Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

202
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda