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

167
Views
Use an array as a reference for initials/shortcuts

I've got datas from an external source that uses initials to refer to specific type of data

Initial Value
A Attelé
AB Abajour
B Base
... ...

I want to be able to get back the value. As I know the value for each shortcuts, I could do something like that :

function getValue(initial)
{
    if(initial == "A") return "Attelé";
    else if(initial == "AB") return "Abajour";
    else if(initial == "B") return "Base";
}

But this is not a good practice as I will have to add a new comparaison for every initial

So i'm thinking about using two array as references :

var values = ["Attelé","Abajour","Base"];
var initialList = ["A", "AB","B"];

function getValue(initial)
{
    var index = initialList.indexOf(initial);
    if(index > -1) return values[index];
    else return null;
}

console.log(getValue("A"));

But here again, i think there is a better practice. To add a new initial, I still have to modify two variables, and if my arrays's length are not matching I could have an issue with the result. I would like to be able to change only one variable.

Hence my question : How can I use one object/array/table to match my initials, and what is the best practice to look at ?

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

0

Can you not just put the data in an object

const names = {
  "a": "Attelé",
  "b": "Base"
}

and then access the data by using

names["a"]
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!