I feel like this is really simple, but how would I check to see if month exists in my jSON data. Using .hasOwnProperty doesn't seem to be working for me. I feel like I'm missing something simple here. All it does is always default to the else clause even though month is clearly in my JSON.
JS Fiddle: http://jsfiddle.net/8y7rJ/1/
var data={"users":[
{
name:"Ray",
phone:"999-999-9999",
birthday: {
month:"January",
day:12,
year:2012
}
},
{
name:"Joe",
phone:"111-999-9999",
birthday: {
year:1992
}
},
{
name:"James",
phone:"111-111-1111",
birthday: {
year:2012
}
}
]}
if(data.users[0].hasOwnProperty("month")){
alert('month exists');
} else {
alert('month does not exist');
}
Code samples are appreciated.
data.users[0]doesn't have a propertymonth.data.users[0].birthdaydoes.