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

135
Views
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
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!