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
  • 31,309
  • 66
  • 224
  • 364

1 Answers1

1

use the parenthesis notation: ()

myPromise.then(r => ({data:r.data, urls:r.list}));
Unamata Sanatarai
  • 6,475
  • 3
  • 29
  • 51
raksa
  • 898
  • 6
  • 17