Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

289
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

0

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

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda