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

149
Views
How to ignore null/undefined value when mapping on an array?

How can I implement this?

I want to map through the plans array and for each item render a list. while This is working, in case if we have null or undefined on a title, we still have 4 Li tag renders which the second one doesn't have any content. but how can I implement this if the title is null/undefined the object get ignored and move to next object and render the rest of the array.

Hope my explanation is clear.

import React from "react";


const App = (props) => {

  const plans = [
    {
      title: "Starter",
      plan: "plan_0",
    },
    { title: undefined,
      plan: "plan_1A",
    },
    {
      title: "Classic",
      plan: "plan_2A",
    },
    {
      title: "Premium",
      plan: "plan_3A",
    },
  ];


  return (
    <div>

      <h1>Notes</h1>
   
      <ul>
        {plans.map((plan, i) =>
            <li className="something" key={i}>
              <span className="somethingels">{plan.title}</span>
            </li>
        )}

      </ul>

    </div>
  );
};

export default App;

at the moment its render like this :

  • Starter
  • Classic
  • Premium
  • <li>Starter</li>
    <li></li>
    <li>Classic</li>
    <li>Premium</li>
    
    about 4 years ago · Juan Pablo Isaza
    2 answers
    Answer question

    0

    Just adding a conditionnal statement should do the trick :

        {plans.map((plan, i) =>
            { plan.title &&
                <li className="something" key={i}>
                    <span className="somethingels">{plan.title}</span>
                </li>
            }
        )}
    
    about 4 years ago · Juan Pablo Isaza Report

    0

    check to see that plan has a property of title before rendering a list item :)

      <ul>
        {plans.map(
          (plan, i) =>
            plan.title && (
              <li className="something" key={i}>
                <span className="somethingels">{plan.title}</span>
              </li>
            )
        )}
      </ul>
    
    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!