0

Below is my code I have question.

  const joinedProducts = products.map(product => ({
    id: product.id,
    name: product.name,
    price: product.price,
    thumbnail_image: product.thumbnail_image,
    categories: productCategoriesObj[product.id],
    options: productOptionsObj[product.id]
  }))

I think argument of Array.map is callback function. But my code is callback function but after arrow, It is not started curly brakets and it is started with parentheses.

How does it works starting with parentheses in callback function.?

I'm expecting MDN documentation about javascript Array.prototype.map(). And I'm expecting How does callback function starting with parenthesis in array.map() works.

Jay Lee
  • 11
  • 2
  • 1
    _TL;DR_ `() => ({ ... })` is equivalent to `() => { return { ... }; }` – Phil Feb 13 '23 at 02:37
  • It's not related to `Array.prototype.map()` function, `Array.prototype.map()` take callback function as a first argument and that doesn't matter normal function or arrow function. So basically your question is related to arrow function and arrow function doesn't required curly braces if you have single line of expression and in your code `()` make single line expression – Arif Khan Feb 13 '23 at 02:38

0 Answers0