What you'd probably have to do is loop over the structs in the address_components array, checking the "types" of each one. When types contains "postal_code", then tada, that's your postcode.
Something like the following code (which worked for me):
<script type="text/javascript">
var stuData =
{
"results": [{
"address_components": [{
"long_name": "44",
"short_name": "44",
"types": ["street_number"]
}, {
"long_name": "Homer Street",
"short_name": "Homer St",
"types": ["route"]
}, {
"long_name": "London",
"short_name": "London",
"types": ["locality", "political"]
}, {
"long_name": "Greater London",
"short_name": "Gt Lon",
"types": ["administrative_area_level_2", "political"]
}, {
"long_name": "United Kingdom",
"short_name": "GB",
"types": ["country", "political"]
}, {
"long_name": "W1H 4NW",
"short_name": "W1H 4NW",
"types": ["postal_code"]
}, {
"long_name": "London",
"short_name": "London",
"types": ["postal_town"]
}
],
"formatted_address": "44 Homer Street, London, Greater London W1H 4NW, UK",
"geometry": {
"location": {
"lat": 51.51981750,
"lng": -0.16534040
},
"location_type": "ROOFTOP",
"viewport": {
"northeast": {
"lat": 51.52116648029151,
"lng": -0.1639914197084980
},
"southwest": {
"lat": 51.51846851970851,
"lng": -0.1666893802915020
}
}
},
"types": ["street_address"]
}
],
"status": "OK"
};
var myPostcode;
for (var i = 0; i < stuData.results[0].address_components.length; i++) {
for (var j = 0; j < stuData.results[0].address_components[i].types.length; j++) {
if (stuData.results[0].address_components[i].types[j] == "postal_code") {
myPostcode = stuData.results[0].address_components[i].long_name;
break;
}
}
}
console.log(myPostcode);
</script>