title: parsing JSON data with java script
body: <p>I use Google plus API and get this data from it and get an error while parsing this JSON data</p>
  
  <p><a href="https://i.stack.imgur.com/pgOM9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pgOM9.png" alt="first part of json data that i parsing "></a></p>
  
  <p><a href="https://i.stack.imgur.com/GvzlG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GvzlG.png" alt="enter image description here"></a></p>
  
  <p>and here is the code I use to parse this data and get error as data object is tested and work fine and hold data as it appear in past 2 images</p>
  
  <pre><code>var allIems = data.items;
  for (var element in allIems) {
    document.getElementById('datafromapi').innerHTML +=
      (" , published time :" + element.published +
        " , last updated time :" + element.updated +
        ", complete url : " + element.url
  
      );
    var obj = element.object.attachments;
  
    document.getElementById('datafromapi').innerHTML +=
      (+"\nattachments of post :\n" +
        " type : " +
        obj[0].objectType +
        " ,displayName of content : " +
        obj[0].displayName +
        " ,content URL  : " +
        obj[0].url +
        " ,content data :" +
        obj[0].image.url +
        " ,content type : " +
        obj[0].image.type +
        " ,content height : " +
        obj[0].image.height +
        " ,content width : " +
        obj[0].image.width +
        "\n\n\n");
  
  
  }
  });
  </code></pre>
  
  <p>i got that error appear </p>
  
  <blockquote>
    <p>Uncaught TypeError: Cannot read property 'attachments' of undefined</p>
  </blockquote>