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

168
Visualizações
Is it possible to have multiple keys for a single value in Javascript?

I'm writing a program that cycles through a dictionary with a list of every state's abbreviation and minimum wage, where the abbreviation is the key and the minimum wage float is the value. However, it occurred to me that many people would not know their state's abbreviation. Is there a way to have multiple keys, so that the user could input either "Delaware" or "DE" and get the same output value? I know I could just create another entry into the dictionary with the same value and the key name of the state, but I'm interested about whether I can manage complexity with this.

Pretty much all I've tried is putting commas on the key value side. I know putting 50 extra keys with the state names is always a possibility, I just wonder if I can manage complexity in a different way.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

I do not understand why you have to take input from user, where you could just give a selectbox in the UI. Anyways I am assuming, thats not possible in your case. If you really need to keep all the possible state's abbreviation input in an object (dictionary), you can keep it in an array. Keep in mind that its not an optimal way of handling the situtation.

const obj = {
  abbreviations: ['DE', 'Delware', 'DRE' ],
  minimumWages: 10
}

Then you can find the wages by doing -

const userInput = 'DE'
if(obj.abbreviations.indexOf(userInput)!== -1) {
  return obj.minimumWages;
}
about 4 years ago · Juan Pablo Isaza Relatório

0

You can do a simple configuration that you transform in dictionary like this

const config = {
 DE : {alias:['Delaware', 'DE'], //every alias
       minimunWage: 10
       }
}

const dictonary = Object.entries(config).reduce((o, [k, v]) => {
  v.alias.forEach(a => {o[a] = v.minimunWage})
  return o
}, {})

console.log(dictonary['DE'])
console.log(dictonary['Delaware'])

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