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

124
Visualizações
for of loop unable to loop through values of an object which has been treated as an array in reactjs

The renderRow() is a method in a React class component which is to get key-values of the state operators object and pass the values of the object into a react component arithmeticComponent to be rendered but its unable to produce the values after calling a for loop upon each map on the key. the issue is the value of the object is unable to be passed as a prop into the arithmeticComponent

 state = {
        operators: {
          topOperators: ["C", "Mod", "<"],
          numbers: ["%", ".", 0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
        },
      };




 renderRow() {
        {
          Object.entries(this.state.operators).map((entry, index) => {
            //   console.log(entry);
            let key = entry[0];
    
            let value = entry[1];
            console.log(value);
    
            for (let val of value) {
              console.log(value.length);
              //console.log(key, value);
              return (
                <Row className="Row">
                  {console.log(val)}
                  <ArithmeticComponent key={index} operator={val} value={val} />;
                </Row>
              );
            }
    
            console.log(key, value);
          });
        }
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

     state = {
        operators: {
          topOperators: ["C", "Mod", "<"],
          numbers: ["%", ".", 0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
        },
      };




 renderRow() {
          return Object.values(this.state.operators).map((value) => value.map(v=>(
               <Row className="Row">
                  <ArithmeticComponent key={v} operator={v} value={v} />;
                </Row>
            ))
          );
        }

use the return statement in Array.map carefully

and should not use index be the key

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