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

126
Visualizações
How would I get a specific nested value from a fetch POST response?

I have made a POST request like this:

var myHeaders = new fetch.Headers();
        raw = "srvrwd-ui=useMe"

        var requestOptions = {
        method: 'POST',
        headers: myHeaders,
        body: raw,
        redirect: 'follow'
        };
        
        fetch("https://www.example.net", requestOptions)
        .then(response => response.text())
        .then(result => console.log(result))
        .catch(error => console.log('error', error));

In console it does print the result and it comes out like this

{"totalResponse":{"details":false},"address":{"number":"234"}}

I want to get the value of number and the methods I have used to extract it specifically is the following:

.then(result => console.log(result["number"]))

which returns undefined

.then(result => console.log(result.totalResponse.address.number))

returns undefined again.

Is there any way I could get the specific value?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You are very close, totalResponse and address are two separate properties, so it would be

.then(result => console.log(result.address.number))

It would probably be beneficial for you to review this documentation https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_Objects as it will explain working with objects quite well.

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