JRough
unread,Jun 21, 2017, 5:18:52 PM6/21/17You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
I am getting undefined in console.log. What is wrong? thanks,
var data = [
{
"cityId": "574",
"cityAndState": "Allen, TX"
},
{
"cityId": "722",
"cityAndState": "Arlington, TX"
},
{
"cityId": "1736",
"cityAndState": "Carrollton, TX"
},
{
"cityId": "1737",
"cityAndState": "Dallas, TX"
},
{
"cityId": "1739",
"cityAndState": "Baltimore, MD"
},
{
"cityId": "1740",
"cityAndState": "Ann Arbor, MI"
},
{
"cityId": "1741",
"cityAndState": "Detroit, MI"
},
{
"cityId": "1742",
"cityAndState": "Royal Oak, MI"
},
{
"cityId": "1743",
"cityAndState": "Maddison Heights, MI"
}
]
var iterateData = function(data){
var ids = [];
if (data.hasOwnProperty(key)){
for (var key in data){
if( data[key].cityAndState == "Carrollton, TX" || data[key].cityAndState =="Allen, TX"){
ids.push(data[key].cityId);
console.log(ids);
}
}
}
console.log(ids);
}
iterateData(data);