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

171
Visualizações
How to display a specific value from JSON object. Example i wanted to display the value of Low and then assign to a variable in React.js

Here is the JSON object where i wanted to display on of the values

"asset_risks": [
    {
        "Medium": 2
    },
    {
        "High": 11
    },
    {
        "Low": 3
    }
],
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

One solution is to combine all object inside the asset_risks array into a single object and then get its attribute like this:

const data = {
  "asset_risks": [
    {
      "Medium": 2
    },
    {
      "High": 11
    },
    {
      "Low": 3
    }
  ]
};

const combined = Object.fromEntries(data.asset_risks.map(Object.entries).flat());

console.log(combined);
console.log(combined.Low);

about 4 years ago · Juan Pablo Isaza Relatório

0

Couple of ways to do that.

One way is you can make use of javascript filter. You can filter out the array based on Low and take the value from the filtered array.

Another way is to make use of find. Please check out the code below for reference.

var obj = {
"asset_risks": [
    {
        "Medium": 2
    },
    {
        "High": 11
    },
    {
        "Low": 3
    }
]
}
console.log(obj.asset_risks.find(obj => obj.Low).Low);
console.log(obj.asset_risks.filter(obj => { return obj.Low })[0].Low);

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