Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

107
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda