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

292
Visualizações
Creating a dictionary in javascript from a fetch request

I am trying to feed a fetch request json htmlcontent into a dictionary but keep getting 'invalid syntax :' errors and as a primarily python person I am pulling my hair out trying to figure out why.

A basic version of the syntax looks as follows:

fetch(URL).then(result => result.json()).then(data => {"Data":data['htmlcontent']});

Can someone point me in the right direction here? Thanks for any and all help.

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

0

To return an object literal from an arrow funtion, you need to wrap it in an extra set of parentheses - not entirely intuitive I agree.

fetch(URL).then(result => result.json()).then(data => ({"Data":data['htmlcontent']}));
// ---------------------------------------------------^----------------------------^

The other option is to use a traditional return syntax - but its a bit longer with extra {}

fetch(URL).then(result => result.json()).then(data => { 
     return {"Data":data['htmlcontent']};
});
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