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

139
Vistas
Conditionally define array object elements based on a specific condition

I have the following menu array:

myMenu: [      
  { id: 'New Job', active: false, href: '/new-job' },
  { id: 'Delete Jobs', active: false, href: '/delete-job' },
  { id: 'All Jobs', active: false, href: '/all-jobs' }
]

Now based on a condition, I want to be able to conditionally display or not display specific array object elements within my myMenu array.

For instance, a user may not have access to create a new job and so, I would like to hide the following element, so that it's not rendered on the left menu nav, that is:

{ id: 'New Job', active: false, href: '/new-job' },

I tried the following but it didn't work:

myMenu: [   
  hasAccess(user) ?
     { id: 'New Job', active: false, href: '/new-job' }
  : {},
  { id: 'Delete Jobs', active: false, href: '/delete-job' },
  { id: 'All Jobs', active: false, href: '/all-jobs' }
]

So basically, if hasAccess(user) is true then I expect the following array to be rendered:

myMenu: [      
  { id: 'New Job', active: false, href: '/new-job' },
  { id: 'Delete Jobs', active: false, href: '/delete-job' },
  { id: 'All Jobs', active: false, href: '/all-jobs' }
]

otherwise render:

myMenu: [      
  { id: 'Delete Jobs', active: false, href: '/delete-job' },
  { id: 'All Jobs', active: false, href: '/all-jobs' }
]
about 4 years ago · Juan Pablo Isaza
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