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

99
Visualizações
Get JSON values as an array in JavaScript

I have JSON content as follows

jsonList = {
    "0": {
        "Name": "Virat Kohli",
        "Runs": "6283",
        "Matches": "207",
        "Average": "37.39",
        "Strike Rate": "129.94",
        "Half Centuries": "42",
        "Centuries": "5",
        "Team": "Royal Challengers Bangalore"
    },
    "1": {
        "Name": "Shikhar Dhawan",
        "Runs": "5784",
        "Matches": "192",
        "Average": "34.84",
        "Strike Rate": "126.64",
        "Half Centuries": "44",
        "Centuries": "2",
        "Team": "Delhi Capitals"
    },
    "2": {
        "Name": "Rohit Sharma",
        "Runs": "5611",
        "Matches": "213",
        "Average": "31.17",
        "Strike Rate": "130.39",
        "Half Centuries": "40",
        "Centuries": "1",
        "Team": "Mumbai Indians"
    },
    "3": {
        "Name": "Suresh Raina",
        "Runs": "5528",
        "Matches": "205",
        "Average": "32.51",
        "Strike Rate": "136.76",
        "Half Centuries": "39",
        "Centuries": "1",
        "Team": "Chennai Super Kings"
    }
}

I get the value of "Virat Kohli" as

name = jsonList[0].Name

I am working to get all the Names in one array and Runs in one array like

names = ['Virat Kohli','Shikhar Dhawan','Rohit Sharma','Suresh Raina']
runs = [6283,5784,5611,5528]

I know I can do this using for loop. But is there any other way that is more efficient than for loop?

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

0

First, transform that Obj into an array:

const arr = Object.values(jsonList)

Then, get the information you need by using .map function:

const names = arr.map(el=> el.Name)
const runs = arr.map(el=> el.Runs)
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