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

166
Views
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 answers
Answer question

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 Report

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