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

133
Visualizações
React map method return currentElement.name where name inside another array

Hi i just want to render a table where name column name and its value dynmamically fetch from an api .. and I store column value in an new array ; I want to return rows value that link with column name in a row

const element = [ "ENDURANCE", "SPEED", "AGILITY", "STRENGTH" ] // this is my column name

api data of rows value

 
​
[
    {
        AGILITY: 1
        ENDURANCE: 1
        SPEED: 1
        STRENGTH: 1
        _id: "62c53266b631f27c54db8d89"
        date: "7/6/2022"
    }, {
        AGILITY: "4"
        ENDURANCE: "4"
        SPEED: "6"
        STRENGTH: "2"
        _id: "62c5a047a053c4ebb5de8c10"
        date: "7/6/2022"
    },
    ​{
        AGILITY: "8"
        ENDURANCE: "6"
        SPEED: "5"
        STRENGTH: "10"
        _id: "62c5a053a053c4ebb5de8c14"
        date: "7/6/2022"
    }
]

I just map this value in table dynamically this is my code ....

 <table className="table">
                    <thead>
                      <tr>
                        <th>/</th>
                        <th>Date</th>

                        {props.data.map((cur, i) => {
                          element.push(cur[0])  //store all column names
                          return <th key={i}>{cur[0]}</th>;
                        })}
                      </tr>
                    </thead>
                    <tbody>
                      {props.stdata.map((curr, index) => {
                        
                        console.log(element);
                        return (
                          <>
                            <tr>
                              <td>{index+1}</td>
                              <td>
                                {curr.date} // date element is same in every api data
                              </td>
                              <td>{
                                curr[element] // may be this is wrong
                                }</td>
                            </tr>
                          </>
                        );
                      
                      })}
                    </tbody>
                  </table>

this is how table looks enter image description here

about 4 years ago · Juan Pablo Isaza
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