How to configure and view listings in Javascript

Using this method to configure enums in javascript, now I would like to search based on another variable in my function below.

Here's the listing of 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

+4
source share
1 answer

Assuming it tenor_unitis something like 0or 1:

var numericValue = _.keys(enums_tenorUnit)[tenor_unit];

however, if tenor_unit- it is something like DAYor WEEK, and then simply:

var numericValue = enums_tenorUnit[tenor_unit];

alternatively, if you are looking for a boolean result, not a literal value, and if tenor_unitsomething like DAYor WEEK, you can use in:

var tenorUnitExists = tenor_unit in enums_tenorUnit;
+3
source

All Articles