How to configure and lookup enums in Javascript

Viewed 1289

Using this technique to setup enums in javascript, I would now like to search based on some other variable in my function below.

Here's the enum config:

var enums_instrumentType = Object.freeze({
    CASH: 0,
    EQUITY: 1,
    COMPOSITE_INDEX:2 ,
    EXCHANGE_RATE:3 ,
    IR_INDEX: 4,
    IR_SWAP_INDEX: 5
});
var enums_tenorUnit = Object.freeze({
      DAY: 0,
      WEEK: 1,
      MONTH: 2,
      YEAR: 3
});

function test(){
   thisInstr = _.findWhere(instrumentsList, { id: mem.instrument_id });  // FIND IT !
   var tenor_unit = thisInstr.ir_index.tenor.unit;     // 0: DAY, 1: WEEK, etc.
   var tenor_size = thisInstr.ir_index.tenor.size;     // number of units

   // HOW TO LOOKUP tenor_unt IN enums_tenorUnit, where tenor_unit is an integer value ???

}

thanks in advance... Bob

1 Answers
Related