Answers for "basic javascript using objects for lookups"

1

Using Objects for Lookups

function phoneticLookup(val) {
  var result = "";

  var lookup = {
     "alpha":"Adams",
     "bravo":"Boston",
     "charlie":"Chicago",
     "delta":"Denver",
     "echo":"Easy",
     "foxtrot":"Frank",
  };
  result = lookup[val];
  return result;
}

phoneticLookup("charlie");
console.log(phoneticLookup("alpha")); // to test
console.log(phoneticLookup("")); //to test
Posted by: Guest on December-17-2020
0

basic javascript using objects for lookups

var alpha = {
  1:"Z",
  2:"Y",
  3:"X",
  4:"W",
  24:"C",
  25:"B",
  26:"A"
};
alpha[2]; // "Y"
alpha[24]; // "C"

var value = 2;
alpha[value]; // "Y"
Posted by: Guest on September-18-2020
0

using objects for lookups in javascript

var alpha = {
  1:"Z",
  2:"Y",
  3:"X",
  4:"W",
  24:"C",
  25:"B",
  26:"A"
};
alpha[2]; // "Y"
alpha[24]; // "C"

var value = 2;
alpha[value]; // "Y"
Posted by: Guest on July-19-2020

Code answers related to "basic javascript using objects for lookups"

Code answers related to "Javascript"

Browse Popular Code Answers by Language