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

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

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