title: What is the proper way to match key and value to some variable using Javascript array?
body: <p>I'm trying to create a function in javascript in order to get a value that match an external variable. </p>
  
  <p>I created an array of key/value. Then I made a function that will check if a value match to a variable. Then i will return the key of this value.</p>
  
  <pre><code>function findNumberFromMonth($data)
  {    
  var obj = {
      01: "Jan",
      02: "Feb",
      03: "Mar",
      04: "Apr",
      05: "May",
      06: "Jun",
      07: "Jul",
      08: "Aug",
      09: "Sep",
      10: "Oct",
      11: "Nov",
      12: "Dec"
      }
  
   for(var element in obj)
           {
               if($data == element.value )
                   {
                       $number = element.key
                   }
            return $number;
           }
  
  }
  </code></pre>
  
  <p>I expected the output of "01" if i initialize $data as "Jan".</p>
  
  <p>But i only got an undefined object.
  How may i process ?</p>
  
  <p>Thank you for your replies.</p>