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

243
Visualizações
How to display all JSON key and value without using key

It maybe basic, but i'm stuck of how to display JSON file in react native For example, i'm get a json object by

const [post, setPost] = React.useState(null);
  const baseURL = 'https://jsonplaceholder.typicode.com/posts/1';
  React.useEffect(() => {
    axios.get(baseURL).then(response => {
      console.log(response.data);
      setPost(response.data);
    });
  }, []);

And it return like

{
    "userId": 1,
    "id": 1,
    "title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
    "body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
}

Now i want to display on screen something like

   1
   1,
   sunt aut facere repellat provident occaecati excepturi optio reprehenderit,
  quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto

I know, i can use post.userId or post.id to display each of them, but if i have 1000 items like this, how can i display them without call keys? i tried

{Object.keys(post).map(i => (
          <Text>{i}</Text>
        ))}

But it return something like

{
    "userId"
    "id"
    "title"
    "body"
}

So how can I display data instead of key without using key?

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

0

You can use Object.values to get the enumerable property values and Array.join to join the resulting array into a string:

const obj = {
    "userId": 1,
    "id": 1,
    "title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
    "body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
}

const res = Object.values(obj).join('\n')

console.log(res)

Your Object.keys approach is also fine - you'll just need to get the value of the property:

const obj = {
    "userId": 1,
    "id": 1,
    "title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
    "body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
}

const res = Object.keys(obj).map(i => obj[i]).join('\n')

console.log(res)

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