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

92
Views
Map array values to string keys in a if statement javascript

I have a list that i want to display in a dropdown. The onchange in handled by

const handleChange = (event) => {
    onFilterChange(filterName, event.target.value);
    }
 };

event.target.value is what is pulling the information.

My dropdown list items are listItems = ['greaterthan', 'lesserthan, 'equal'], which are string keys that are fed into event.target.value.

My issue is that i want listItems to be an array of symbols( >, <, =) instead of words. But my components only works with the word keys.

I want to create an if statement in the handler that maps the word value to the signs array.

ex.

const listItems = ['>','<','=']

const handleChange = (event) => {
        onFilterChange(filterName, event.target.value);
        if (event.target.value === '>') {
          // then use key value of greaterthan
        } if (event.target.value === '<') {
          // then use key value of lesserthan
        } if (event.target.value === '=') {
          // then use key value of equal
        }
      }

;

I'm feeding it into a select component by using

<Select>
{listItems.map((listItem) => <MenuItem value={listItem}>{listItem}</MenuItem>)}
</Select>

Thank you for your help.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can create am object map to retrieve the respective ids :

listItems = {
  ['>']: 'greaterthan',
  ['<']: 'lesserthan',
  ['=']: 'equal'
}

const handleChange = (event) => {
        onFilterChange(filterName, event.target.value);
        if (event.target.value === listItems['>']) {
          // then use key value of greaterthan
        } if (event.target.value === listItems['<']) {
          // then use key value of lesserthan
        } if (event.target.value === listItems['=']) {
          // then use key value of equal
        }
}
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!