title: TypeError: Cannot read property '0' of undefined while accessing "photo_reference" property
body: <p>Below is the JSON i get from the google places API. Parsing the Json with JSON.parse(body). The "results" key is an array of Objects that i am looping through to access the property of photos. Hope the code is clearer now. I have pasted in the valid JSON that i am getting from the api call.</p>
  
  <pre><code>{
     "html_attributions" : [],
     "next_page_token" : "CqQCGwEAAI5PpCTJI6Qoa1CD9iA4EpJha6t0gMlZ3I3DpOIVgE1BUYh5NNI0lXRuvAltI8RhOilTNJggXsR3TEP2C6hoIsibEWZXnZClbEcZzes7LGqJuQ0heJWipe7RNbxq8S8zuao1HWfECs11i44WO0Luv-4bYx5GlCEj6Wl07LitkzwG4u0e4FyIHogyaShky5Awd44ZyOcqKzy7wYBr7p37j6A6PMdR7zn7cMWQKiVolfHQbFZerVJ3JJ5MiKSshocG189wPKjqJzSACE6W19LmZ7TIMB9qm7jQANNQStrsq7rYAWIBQ-UqJ_6Hv9jv1xL7eRQ9bkyR17u7xPZWfeCU69u_PQmGvuvSWNJDvNUuoI-uwLc_RhgTZp26kyzMlXwYHRIQXy13ridwzgvlBU8ez_y-WBoUcBN7UvN8Q8iuDyS_LjXEWmT_sIk",
     "results" : [
        {
           "geometry" : {
              "location" : {
                 "lat" : 28.615572,
                 "lng" : 77.3468
              },
              "viewport" : {
                 "northeast" : {
                    "lat" : 28.6169209802915,
                    "lng" : 77.34814898029151
                 },
                 "southwest" : {
                    "lat" : 28.6142230197085,
                    "lng" : 77.34545101970849
                 }
              }
           },
           "icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png",
           "id" : "dea8496f678dc1f01381a85298e37a0905a3ca11",
           "name" : "Malabar Junction Restaurant",
           "opening_hours" : {
              "open_now" : true,
              "weekday_text" : []
           },
           "photos" : [
              {
                 "height" : 746,
                 "html_attributions" : [
                    "\u003ca href=\"https://maps.google.com/maps/contrib/117230637789134827076/photos\"\u003eSwati\u003c/a\u003e"
                 ],
                 "photo_reference" : "CmRaAAAArbpjr1fjNp2Fc4ww8Vkgrzzzt5aHEvACzEZFa-XCJU3Fw2JqFLSDo64jlFWwDZwdYaFP_cIgdqI37TJ25mVB2W_rtoTv_aI0LJGgnh_P4-UF7u45ZvqdM-bE4ljYD2yyEhDjv-4AWC5AKcE713GL1qAsGhQjAN2oS1KWv52f8XsjEK3Pmnv53w",
                 "width" : 750
              }
           ],
           "place_id" : "ChIJx6qqqj3lDDkRcBw22oTfWgk",
           "reference" : "CmRRAAAAZBpNfAiO2G_y57bLoFTSM28MG4xUi-VAg3kJgV2ZzksdhpzySwxdPNdPP1paEIE46i70oxgLHliUcEjxalukNEyhN85J-ryRbXVVMkg4Tz-MGBGhgVur7SV5b4IFePnfEhABXu9pHswL4Up5w-k9td94GhSDs13DRQVxPOpI8iWqUbLyd_WJUg",
           "scope" : "GOOGLE",
           "types" : [ "restaurant", "food", "point_of_interest", "establishment" ],
           "vicinity" : "62, 8, Rani Jhansi Marg, Block 10, Sector 10, Noida"
        }
     ],
     "status" : "OK"
  }
  </code></pre>
  
  <p>Trying to Access the photo_reference property like so </p>
  
  <pre><code>let resultJSON = JSON.parse(body);
  let results = resultJSON["results"];
  for (var i = 0; i &lt; results.length; i++) { 
     let name = results[i]["name"];
     console.log(results[i].photos[0].photo_reference);
  }
  </code></pre>