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

242
Visualizações
In react and javascript, how can i map this objects key values correctly?

I have an object where each key is a unique id, and that keys value is an array of objects.

I have a prop, lets call it 'objId' whos value is one of the unique ids on the object

I want to map the array on the object where its key matches the prop 'objId'

To give a better visual example:

const bigObj = {
  a123: [{status: 'happy'}, {status: 'moody'}]
  a456: [{status: 'fail'}, {status: 'blah'}]
}

const objId = 'a123'

I want to map bigObj.a123 into my component because that matches the objId prop.

I'm kinda stuck and any ideas would help, can provide more info if needed as well.

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

0

You can access the object property like this:

const arr = bigObj[objId];

Then you can map it into whatever you need. You would also need to be careful and check if the array actually exists:

const mappedArray = arr?.map(item => "whatever you need to map it into");
about 4 years ago · Juan Pablo Isaza Relatório

0

Iterate the object keys

Object.keys(bigObj).map(key => {
   //put your logic here for keys and values e.g. key, bigObj[key]
   bigObj[key].map(obj => {
      //put your logic here for nested array object

   });
});
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