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

282
Visualizações
Check for multiple array indexes in react/typescript, whether one exists?
if(inputData.info[0].instruction){
  return (
  <Text ref={instructionContainerRef} dangerouslySetInnerHTML={{ 
    __html: replaceTextLinks(inputData.info[0].instruction) 
    }}>
  </Text>
)
  }
  else {
    return null
  }

So the possible index positions for the inputData.info] index are 0-68. How can I achieve to check whether there exists data for an array index between 0-68, and if it finds one than then to return the if statement with this array index?

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

0

Well, what about:

function checkItems(info, length) {
  return Array
    .from(Array(length).keys())
    .map((_, i) => info[i] && info[i].instruction)
    .filter(item => item).length === length;
}

let index = 14;

return checkItems(inputData.info, 68) ?
  <Text ref={instructionContainerRef} dangerouslySetInnerHTML={{ 
  __html: replaceTextLinks(inputData.info[index].instruction) 
  }}> :
  null;
about 4 years ago · Juan Pablo Isaza Relatório

0

inputData.info.find(inf => !!inf) will return the first object that is not null or undefined.

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