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

375
Visualizações
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 Respostas
Responde à pergunta

0

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

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 Relatório

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 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