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

103
Vistas
How to return properties of a response object along with a new object?

So I am making a POST request like so:

async createVisit(patientId: string, visitorId: string) {
  const userJWT = jwt.sign(
    {
      _id: visit,
      refreshCount: 0
    },
    this.localConfig.spirit.jwtSecret
  )
  const visitURL = this.localConfig.spirit.url
  let response = await fetch(visitURL, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Authorization': 'Bearer' + userJWT
    },
    body: JSON.stringify(visit)
  });
  if (response.ok) {
   let result = await response.json();
  }
}

So I need to return couple of properties out of that result along with a new object to access inside the method of another class.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can only return 1 thing from a function, but if you do need to return 2 things, you can combine them in an array

return [coupleOfPropertiesFromResult, newObject];

You can also use an object.

...
let result = await response.json();

return { 
  prop: result.prop,
  another: result.another,
  yetanother: 42 
}
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