Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

93
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda