1

I'm trying to get a property name if I know value from object defined as

expOperators = {
    "0": "Select operator",
    "GREATERTHAN": "After",
    "LESSTHAN": "Before",
    "GREATERTHANEQUALTO": "On or After",
    "LESSTHANEQUALTO": "On or Before",
    "EQUALS": "On",
    "BETWEEN": "Between",
    "ISNULL": "Is Null",
    "ISNOTNULL": "Is not Null"
};

Obviously if I need to find value it would be easy, but I need to accomplish an opposite task, knowing value find out what is the property. Any idea?

Cheran Shunmugavel
  • 8,319
  • 1
  • 33
  • 40
AlexKu
  • 45
  • 7

2 Answers2

0

You'll have too loop through the object and compare the object values to what you're looking for.

expOperators = {
    "0": "Select operator",
    "GREATERTHAN": "After",
    "LESSTHAN": "Before",
    "GREATERTHANEQUALTO": "On or After",
    "LESSTHANEQUALTO": "On or Before",
    "EQUALS": "On",
    "BETWEEN": "Between",
    "ISNULL": "Is Null",
    "ISNOTNULL": "Is not Null"
};

for(var name in expOperators ) {
    if(expOperators[name] === "Between"){
        document.write(name);
    }
}

http://jsfiddle.net/WsjyS/2/

cillierscharl
  • 7,043
  • 3
  • 29
  • 47
bluetoft
  • 5,373
  • 2
  • 23
  • 26
0

use something like this

 for(var name in expOperators ) {
    if(expOperators.hasOwnProperty(name)){
      if(expOperators[name] === "Between"){
         alert(name);
       }
    }
}
rajesh kakawat
  • 10,826
  • 1
  • 21
  • 40