showing results for - "using objects for lookups in javascript"
Erik
27 Mar 2017
1function phoneticLookup(val) {
2  var result = "";
3
4  var lookup = {
5     "alpha":"Adams",
6     "bravo":"Boston",
7     "charlie":"Chicago",
8     "delta":"Denver",
9     "echo":"Easy",
10     "foxtrot":"Frank",
11  };
12  result = lookup[val];
13  return result;
14}
15
16phoneticLookup("charlie");
17console.log(phoneticLookup("alpha")); // to test
18console.log(phoneticLookup("")); //to test
19
Matteo
22 Oct 2018
1var alpha = {
2  1:"Z",
3  2:"Y",
4  3:"X",
5  4:"W",
6  24:"C",
7  25:"B",
8  26:"A"
9};
10alpha[2]; // "Y"
11alpha[24]; // "C"
12
13var value = 2;
14alpha[value]; // "Y"
15
Ianthe
14 Oct 2016
1var alpha = {
2  1:"Z",
3  2:"Y",
4  3:"X",
5  4:"W",
6  24:"C",
7  25:"B",
8  26:"A"
9};
10alpha[2]; // "Y"
11alpha[24]; // "C"
12
13var value = 2;
14alpha[value]; // "Y"
similar questions
queries leading to this page
using objects for lookups in javascript