Search code examples
jqueryhashprototypejs

Convert this prototype hash to plain javascript/jquery?


I need to get rid of prototype from a site so I need to convert this:

var moduleCodeHash = new Hash();
moduleCodeHash.set('SHIPMANAGER','SHIPMENTFILTER');
moduleCodeHash.set('TRAFFICMGR','TRAFFICMGRFILTER');
moduleCodeHash.set('SHIPBIDMONITOR','BIDFILTER');

moduleCodeHash.get(selectedValue);

to plain js or jquery


Solution

  • If you're not doing anything fancy with it then don't make it fancy, use an ordinary object.

    var moduleCodeHash = {};
    moduleCodeHash['SHIPMANAGER']    = 'SHIPMENTFILTER';
    moduleCodeHash['TRAFFICMGR']     = 'TRAFFICMGRFILTER';
    moduleCodeHash['SHIPBIDMONITOR'] = 'BIDFILTER';
    
    moduleCodeHash[selectedValue]; // get selectedValue