return -1 Returns array index if found, or -1 if not found. Checking for undefined-ness is not an accurate way of testing whether a key exists. What if the key exists but the value is actually undefined? Use this code snippet to check by id if an element exists in your document: if(document.getElementById(idofelement)) alert(element exists!) You can achieve a similiar result using jQuery Okay, I think what you want to do is this. If (data.flightStatuses.length > i). Var estimatedGateDeparture data.flightStatuses[i].operationalTimes.estimatedGateDeparture.