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

372
Vistas
how to get all the values inside JSON with a common name?

I need to get an array of all the name values from a JSON structure.

My JSON looks like this:

{
  "profile": {
    "G5j7": {
      "name": "siddharth",
      "age": "17"
    },
    "Loj9": {
      "name": "ram",
      "age": "20"
    },
    "Huy8": {
      "name": "maix"
    }
  }
}

I can get a specific name value by:

var singleName = profile.G5j7.name;

But how do I get an array of all the name values if don't know all the IDs inside profile? I need to store in a variable.

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

const arrayName = Object.values(profile).map((item) => item.name);
about 4 years ago · Juan Pablo Isaza Denunciar

0

You can use Object.keys to get all properties keys in an Object, with that you can get access to all profile object keys with that you can retrieve name for each key like bellow

let data = {
    "profile": {
        "G5j7": {
            "name": "siddharth",
            "age": "17"
        },
        "Loj9": {
            "name": "ram",
            "age": "20"
        },
        "Huy8": {
            "name": "maix"
        }
  }
};

let profiles_keys = Object.keys(data.profile);

let results = profiles_keys.reduce((accumulator, current)=> {
    return accumulator.concat(data.profile[current].name)
}, []);

console.log(results);

about 4 years ago · Juan Pablo Isaza Denunciar

0

Object.values(yourObj.profile).map(v => v.name)

Object.values() returns an array of the values on every (own) prop of your object. So you can forget about the property names and iterate on its values

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