title: Can't access fields of a Javascript Object
body: <p>The following Javascript function returns a JS object:</p>
  
  <pre><code>function getCookies() {
      var result = {};
      var cookie = {};
      var cookies = document.cookie.split(';');
      for (var i = 0; i &lt; cookies.length; i++) {
          cookie = cookies[i].split('=');
          result[cookie[0]] = cookie[1];
      }
      return result;
  }
  </code></pre>
  
  <p>When I tried to access its fields the "easy" way, all I got was "undefined", eg:</p>
  
  <pre><code>var c = getCookies();
  alert(c.a_cookie_name);
  alert(c['a_cookie_name']);
  </code></pre>
  
  <p>The only way I could access the keys and values was iterating through the fields, eg:</p>
  
  <pre><code>for(cookieName in c){
    alert(c[cookieName]);
  }
  </code></pre>
  
  <p>The question is how to access the fields without iterating?</p>
  
  <p>Thank you.</p>
  
  <p>P.S. The keys and values do exist, I can see the object fields with console.log(getCookies()) in Chrome.</p>