Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

283
Views
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 answers
Answer question

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 Report

0

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

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!