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

145
Visualizações
mapping json into react table

I think I have pretty easy question, but can't figure it out by my own. I am trying to map json object into table in react. Each key represent a column, and each value in the array is a row. How should I map it to achieve table structure like example below?

Json structure:

{
  "code": [
    "111111",
    "222222",
    "333333"
  ],
  "name": [
    "nameA",
    "nameB",
    "nameB"
  ],
  "price": [
    1,
    2,
    3,
  ]
}

Structure of the table should be like:

code name price
111111 nameA 1
222222 nameB 2
333333 nameC 3
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Something like this would work with your structure of js object or json . The problem is your structure should be changed to make it easier to iterate through.

    class Table extends React.Component {
        constructor(props) {
            super(props)
            this.state = {
                
            }
        }
        
        render() {
            var abc={
                "code": [
                    "111111",
                    "222222",
                    "333333"
                ],

                "name": [
                    "nameA",
                    "nameB",
                    "nameB"
                ],
                "price": [
                    1,
                    2,
                    3,
                ]
            }
            
            var trArr=[]
            var tb=function(){
                    abc.code.map(function(v,i){
                            trArr.push(
                                <tr key={i}>
                                    <td>{abc.code[i]}</td>
                                    <td>{abc.name[i]}</td>
                                    <td>{abc.price[i]}</td>
                                </tr>   
                            )
                    })
            
                    return(
                                    <table>
                            <thead> 
                            <tr><th>code</th><th>name</th><th>price</th></tr>
                            </thead>
                            <tbody>
                            {trArr}
                            </tbody>
                        </table>

                    )

            }()
        
            return (
            <div>
                {tb}
            </div>
            )
        }
}

Your structure should look more like this, so you can iterate/map over it as individual container records and not split up columns/values in separate arrays

[{
    "code": "11111",
    "name": "nameA",
    "price": 1
  },
  {
    "code": "22222",
    "name": "nameB",
    "price": 2
  },
  {
    "code": "33333",
    "name": "nameC",
    "price": 3
  }
 ]
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