title: Angular 2 get key and value from json array with dynamic key
body: <p>I want to get key and value from json array with dynamic keys. Meaning, I don't know in advance what will be the keys.</p>
  
  <p>This is an example to the json the function gets:</p>
  
  <pre><code>arr = [
         {key1: 'val1'},
         {key2: 'val2'},
         {key3: 'val3'}
        ];
  </code></pre>
  
  <p>It seems simple to me but I am unable to get the key and value for each item.</p>
  
  <p>This is what I tried (based on <a href="https://stackoverflow.com/questions/35534959/access-key-and-value-of-object-using-ngfor/this%20pipe">this pipe</a>):</p>
  
  <pre><code>for (let key of arr) {
     console.log ('key: ' +  key + ',  value: ' + arr[key]);
   }
  </code></pre>
  
  <p>But what I get in the log is the following:</p>
  
  <pre><code>key:[object Object], value: undefined
  </code></pre>
  
  <p>My expected behavior is to get the following:</p>
  
  <pre><code>key:key1, value:val1
  </code></pre>
  
  <p>What am I doing wrong? How can I get the keys and values?</p>