0

I returned to new JS after a decade and trying to learn new syntax.

I don't know what is wrong with syntax:

const images = this.props.update.imageUrls.map(imageUrl =>  
    {original:imageUrl,thumbnail:imageUrl} );

It keeps giving error:

UpdateView.js: Unexpected token, expected ; (41:96)
      > 41 |         const images = this.props.update.imageUrls.map(imageUrl =>  {original:imageUrl,thumbnail:imageUrl} );
           |                                                                                                 ^

This old syntax works and does what I want:

const images = this.props.update.imageUrls.map(function(imageUrl,index) {
    return {"original":imageUrl,"thumbnail":imageUrl}} );
melpomene
  • 84,125
  • 8
  • 85
  • 148
thevikas
  • 1,618
  • 1
  • 14
  • 31
  • 2
    Wrap the object in `()` to return as object. `imageUrl => ({original:imageUrl,thumbnail:imageUrl})` – Tushar May 20 '17 at 07:37
  • 1
    Possible Dup of [ECMAScript6 arrow function that returns an object](//stackoverflow.com/q/28770415) – Tushar May 20 '17 at 07:39

0 Answers0