Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

285
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!