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

116
Views
how to skip undefined value from array to prevent unnecessary element in jsx

I want to display array values using map in jsx, but don't want to create element for undefined value. here in below example, mainArray has multiple subarrays, and in last array, last element is undefined. and unnecessary list is getting created for undefined value.

import "./styles.css";

export default function App() {
const d=['link1','link2','link3','link4','link5'];
const mainArr=[];
  var a=[];
  var b=[];
  var c=[];
  for(var i=0;i<d.length;i=i+3){
    a.push(d[i]);
    b.push(d[i+1]);
    c.push(d[i+2]);
   }
  mainArr.push(a,b,c);
   
  
  return (
    <div>
      {
      mainArr.map((link,ind) => {
       return (
          <div>
            <ul>
            {/* <div>{ind}</div> */}
            {
              link.map(item=> {
                return(
                  <li>{item}</li>
                )
              })
            }
            </ul>
          </div>
        )
      })
    }
  </div>
  );
  }
about 4 years ago · Juan Pablo Isaza
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!