Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

198
Visualizações
Vuejs How to assign array object?

I have a response like below from an API call,

{
    "1-2021": [
        {
            "id": 1,
            "status": "New",
            "player_count": 7
        },
        {
            "id": 2,
            "status": "Verified",
            "player_count": 4
        },
        {
            "id": 3,
            "status": "Regitered ID",
            "player_count": 18
        },
        {
            "id": 4,
            "status": "On Playing",
            "player_count": 15
        },
        {
            "id": 5,
            "status": "Finished",
            "player_count": 9
        },
        {
            "id": 6,
            "status": "Active",
            "player_count": 10
        },
        {
            "id": 7,
            "status": "Inactive",
            "player_count": 0
        }
    ],
    "2-2021": [
        {
            "id": 1,
            "status": "New",
            "player_count": 3
        },
        {
            "id": 2,
            "status": "Verified",
            "player_count": 8
        },
        {
            "id": 3,
            "status": "Regitered ID",
            "player_count": 17
        },
        {
            "id": 4,
            "status": "On Playing",
            "player_count": 11
        },
        {
            "id": 5,
            "status": "Finished",
            "player_count": 7
        },
        {
            "id": 6,
            "status": "Active",
            "player_count": 6
        },
        {
            "id": 7,
            "status": "Inactive",
            "player_count": 0
        }
    ]
}

Then, I have to repeat the whole arrays inside the arrays. How do I do that in VueJS?

I have searched for using forEach.. nowhere I found forEach usage.

Can anyone help me on how to fetch the values from that arrays by using either forEach or any else(VueJS)?

I expected the outcome:

chartData: [
        ['Month', 'New', 'Verified', 'Regitered ID', 'On Playing', 'Finished', 'Active', 'Inactive'],
        ['January', 7, 4, 18, 15, 9, 10, 0],
        ['February', 16, 22, 23, 30, 16, 9, 8]
      ]

Thanks & Regards,

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Try this

let a = {
  "1-2021": [{
      "id": 1,
      "status": "New",
      "player_count": 7
    },
    {
      "id": 2,
      "status": "Verified",
      "player_count": 4
    },
    {
      "id": 3,
      "status": "Regitered ID",
      "player_count": 18
    },
    {
      "id": 4,
      "status": "On Playing",
      "player_count": 15
    },
    {
      "id": 5,
      "status": "Finished",
      "player_count": 9
    },
    {
      "id": 6,
      "status": "Active",
      "player_count": 10
    },
    {
      "id": 7,
      "status": "Inactive",
      "player_count": 0
    }
  ],
  "2-2021": [{
      "id": 1,
      "status": "New",
      "player_count": 3
    },
    {
      "id": 2,
      "status": "Verified",
      "player_count": 8
    },
    {
      "id": 3,
      "status": "Regitered ID",
      "player_count": 17
    },
    {
      "id": 4,
      "status": "On Playing",
      "player_count": 11
    },
    {
      "id": 5,
      "status": "Finished",
      "player_count": 7
    },
    {
      "id": 6,
      "status": "Active",
      "player_count": 6
    },
    {
      "id": 7,
      "status": "Inactive",
      "player_count": 0
    }
  ]
};

let ar = [];
let b = Object.keys(a).forEach((e, index) => {



  if (index == 0) {

    let b = a[e].map(r => r.status)

    b.unshift("Month")
    ar.push(b)
  }
  let a1 = [e]

  a[e].forEach(c => {



    a1.push(c.player_count)
    c.status

  })
  ar.push(a1)

})

console.log(ar)

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda