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

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

    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 Denunciar

    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 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