0

I have a array of objects:

const arr = [
  {
    name: "Name 1",
    symbol: "S1"
  },
  {
    name: "Name 2",
    symbol: "S2"
  },
]

And I want to transform this on this

{
  S1: "Name 1", S2: "Name 2"
}

I tried this

arr.map((a) => { [a.symbol]: a.name })

But no luck. How can I achieve this?

evolutionxbox
  • 3,703
  • 5
  • 35
  • 49
Rodrigo
  • 607
  • 1
  • 17
  • 46
  • 2
    When implicitly returing an object in an arrow function, wrap the returning object in parens otherwise the curly braces will be interpreted as a block. `{ [a.symbol]: a.name })` -> `({ [a.symbol]: a.name }))` – evolutionxbox Dec 04 '21 at 13:00

0 Answers0