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

230
Visualizações
Map an array from a JSON file using modern Javascript and push it on a table

I'm trying to build a table from a JSON file using map in react, I've tried two ways, the first one using map and the second one using a for loop, but I got nothing.

I appreciate an ES6 based solution.

map:

const META =
[
  {
    "name": "CeloPunks Celo Connect Edition #377",
    "image": "https://ipfs.io/ipfs/QmRX4tFHKajU9nAxwHqJjkwtvBFCNRwJXNzdqrXUA16o3Z/377.png",
    "edition": 377
  }
];
const Data = META.map(vardata = () => {
  return (
  <div>
      <td>{vardata}</td>
  </div>
  )
});
console.log(Data);

for loop:

const DataAll = [];
for (let i=0; i<=META.lenght; i++){
  DataAll.push(META[i]);
};
console.log(DataAll);

How to create a table from a JSON file like META using modern javascript?

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

0

you may want something like this :

const Table = () => {
  const META = [
    {
      name: "CeloPunks Celo Connect Edition #377",
      image:
        "https://ipfs.io/ipfs/QmRX4tFHKajU9nAxwHqJjkwtvBFCNRwJXNzdqrXUA16o3Z/377.png",
      edition: 377,
    },
  ];

  return (
    <table>
      <thead>
        <tr>
          <th>Name</th>
          <th>Image</th>
          <th>Edition</th>
        </tr>
      </thead>
      <tbody>
        {META.map(({ name, image, edition }) => (
          <tr key={name}>
            <td>{name}</td>
            <td>{image}</td>
            <td>{edition}</td>
          </tr>
        ))}
      </tbody>
    </table>
  );
};

export default Table;

This is just a table with one line and a header, but if you change your META variable, it will loop through the array to display each line… For example with this array :

  const META = [
    {
      name: "First Edition #1",
      image: "https://first-link",
      edition: 1,
    },
    {
      name: "Second Edition #2",
      image: "https://second-link",
      edition: 2,
    },
    {
      name: "Third Edition #3",
      image: "https://third-link",
      edition: 3,
    },
  ];
about 4 years ago · Juan Pablo Isaza Relatório

0

I think you like this below:

const Table = () => {
  const META = [
    {
      name: "CeloPunks Celo Connect Edition #377",
      image:
        "https://ipfs.io/ipfs/QmRX4tFHKajU9nAxwHqJjkwtvBFCNRwJXNzdqrXUA16o3Z/377.png",
      edition: 377,
    },
    {
      name: "CeloPunks Celo Connect Edition #378",
      image:
        "https://pbs.twimg.com/profile_images/1440251297538527243/XQLuZvwr_400x400.png",
      edition: 378,
    },
    {
      name: "CeloPunks Celo Connect Edition #379",
      image:
        "https://cdn.cyberbox.art/cpunk/14.png",
      edition: 379,
    },
  ];

  return (
    <table style={{width:'100%'}}>
      <thead>
        <tr>
          <th>Name</th>
          <th>Image</th>
          <th>Edition</th>
        </tr>
      </thead>
      <tbody>
        {META.map(item => (
          <tr key={name}>
            <td>{item.name}</td>
            <td><img src={item.image} /></td>
            <td>{item.edition}</td>
          </tr>
        ))}
      </tbody>
    </table>
  );
};

ReactDOM.render(<Table />, document.getElementById('root'))
img{
 width: 100px;
}

table, th, td {
  border:1px solid black;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>


<div id='root'></div>

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