0

I have an array which contains several objects.

this is my array:

    const data = 
    [
      {
        name: 'Asep',
        score: 90,
        class: 'adonis'
      },
      {
        name: 'Ahmad',
        score: 85,
        class: 'vuejs'
      },
      {
        name: 'Regi',
        score: 74,
        class: 'adonis'
      },
      {
        name: 'Afrida',
        score: 78,
        class: 'reactjs'
      }
    ]

the result like this

{
   adonis: { name: 'Asep', score: 90 },
   vuejs: { name: 'Ahmad', score: 85 },
   reactjs: { name: 'Afrida', score: 78}
}

so, I want to create an object whose content is an object.

Badrudin
  • 31
  • 3
  • 1
    Iterate over the array and use bracket notation to assign the `name` and `score` in an object with a property name of the `class` using bracket notation – CertainPerformance Dec 22 '22 at 02:34

0 Answers0