Question: I created an object that requires a dictionary object be passed to initialize, and has attributes (like `length`). I'd like to be able to simply access the dictionary's `key : value` pair by passing something like:

`myNewObj['a']` or `myNewObj.a`

and *not* having to instead pass `myNewObj.dictionary['a']`, but can't figure out how to do so.

Is there a way to set a dynamic attribute that, if no other attribute or method exits, will instead look into the dictionary and find the associated key?

```
var newObject = function(dictionary) {
    this.dictionary     = dictionary;
    this.length         = dictionary[[Object.keys(dictionary)[0]]].length;

    this.get = function (column) {
        return this.dictionary[[column]];
    }
};

var myNewObj = new newObject({
    a   : [1,2,3],
    b   : [4,5,6]
});

console.log(myNewObj.get('a'));

```

I've updated this to show a `.get()` method that works, but it's still not exactly what I'm looking for.

jsFiddle: <http://jsfiddle.net/2uMjv/571/>

Answer: 
> 
> As it's a static function i can't use any kind of global variable (like hashmap)
> 
> 
> 

Sure you can.

```
private static final HashMap<String, String> LANGUAGES = new HashMap<>();

static {
  LANGUAGES.put("AD", "ca");
  // TODO: rest of mappings go here
}

private static String countryToLanguage(String countryCode){
  return LANGUAGES.get(countryCode);
}

```
Use a string switch:

```
switch (countryCode) {
  case "AD": return "ca";
  case "AE": return "ar";
  case "AG": return "en";
  // etc.

  default:
    // Do something if not found,
    // e.g. throw IllegalArgumentException,
    // or return a default value.
}

```