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

400
Visualizações
Javascript: map Array of Objects with unknown keys

I have an array of objects with keys that have different names.

    let array = [{"obj1": 1, "obj2": 2}, {"obj3": 3}]

I want to be able to display on the front (react-native) the key and the value. I tried doing so with a map and object.entries but it is not working (Error: Objects are not valid as a React child . If you meant to render a collection of children, use an array instead.):

    {Object.entries(array).map(([key, val] = entry) => {
       return (<Text>{[key, val]}</Text>)
    })

How could I display simply in a Text the key and the value of each object?

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

0

Try this:

{array.map(item => (
  <div>
    {Object.entries(item).map(([key, val]) => {
      return (
        <Text>
          {key} = {val}
        </Text>
      )
    })}
  </div>
))}

Note: please add keys when using in real application

about 4 years ago · Juan Pablo Isaza Relatório

0

You should reduce the array, spread the entries, and then flatten. The result will be an array of key-value pairs.

const array = [{ "obj1": 1, "obj2": 2 }, { "obj3": 3 }]

const keyValuePairs = array
  .reduce((pairs, obj) => [...pairs, Object.entries(obj)], [])
  .flat();

keyValuePairs.forEach(([key, val]) => console.log(key, val));

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