Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

93
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda