title: Use data attribute to retrieve object key's value in javascript (jQuery)
body: <p>Trying to get back values of an object based on a data attribute.
  While I have trouble explaining it with the right lexicon, the set up example should be more clear:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var obj = {
    key1: "hello",
    key2: "Hi",
    key3: 1,
    key4: 2
  }
  
  $(".key").each(function() {
    var dk = $(this).data('key');
    console.log(obj.dk);
  });</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;div class="key" data-key="key1"&gt;&lt;/div&gt;
  &lt;div class="key" data-key="key2"&gt;&lt;/div&gt;
  &lt;div class="key" data-key="key3"&gt;&lt;/div&gt;
  &lt;div class="key" data-key="key4"&gt;&lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Using this manner returns undefined.
  Anyone can help on this matter. Thanks!</p>