title: jQuery each and map to a new object based on data-attribute
body: <p>I'm trying to extract all IDs from multiple elements based on data-attribute.</p>
  
  <p>Here is my html:</p>
  
  <pre><code>&lt;div class="row"&gt;
    &lt;div class="item" data-element='{"id":1, "name":"John"}'&gt;John&lt;/div&gt;
    &lt;div class="item"&gt;&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="row"&gt;
    &lt;div class="item"data-element='{"id":2, "name":"Peter"}'&gt;Peter&lt;/div&gt;
    &lt;div class="item"&gt;&lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>and javascript:</p>
  
  <pre><code>var result = [];
  $('[data-element]').each(function() {
      result = $(this).data('element');
  }); 
  
  $.map(result, function( val, i ) {
     console.log(val)
  });
  </code></pre>
  
  <p>The problem is that I only get the last element. Console log shows 2 Peter.</p>
  
  <p>What I would like to be the final result is all id's as well as names extracted in form of an array like:</p>
  
  <pre><code>id = [1,2]
  name = ['John', 'Peter']
  </code></pre>