title: Get first object from array of objects in react
body: <p>I am trying to get the first object from an array of objects. Fetched data in componentDidMount and return: </p>
  
  <pre><code>var array1 = [
      {
        Id: 1, 
        Categories: 200 
      },
      {
        Id: 2, 
        Categories: 100 
      }
  ]
  </code></pre>
  
  <p>(real data is much more complicated but in the same format)
  What I want is this:</p>
  
  <pre><code>array2 = [
      Id: 1, 
      Categories: 200
  ]
  </code></pre>
  
  <p>I was using </p>
  
  <pre><code>var iterator1 = array1.entries();
  let array2 = iterator1.next().value
  </code></pre>
  
  <p>and when I <code>console.log(array2)</code> it shows the array data (all key and value is in index 1 of array), then when I <code>console.log(array2[1].Id)</code> 
  it shows undefined right inside the render method in class component. I use the same code in other IDE but not using react the code work. Could someone explain to me please? Appreciate for any help. </p>
  
  <p>Edit:
  At the end I found that I asked the wrong question. I failed to get the data because I declared the data in my reducer to object instead of array. I mark the answer by larz since you just need to put index 0 to get the first object from the array of objects.</p>