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

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

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 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