0

Consider:

myPromise.then(r => { return {data:r.data, urls:r.list}});

This works, but that is not:

myPromise.then(r => {data:r.data, urls:r.list});

Because the javascript "thinks" that { is begin of code block, so I have to put return and only then return object.

Is there more compact way which stays with one line then anonymous function, but return object?

Cherry
  • 28,337
  • 55
  • 193
  • 326

1 Answers1

1

use the parenthesis notation: ()

myPromise.then(r => ({data:r.data, urls:r.list}));
Unamata Sanatarai
  • 5,920
  • 3
  • 25
  • 47
raksa
  • 830
  • 6
  • 16