I need to build an array from a returned JSON object using jQuery. This would be alot easier if there were a common naming convention or sub-level for these data keys, I know there's a better way to do it but my jQuery is a little rusty. Thanks!
JSON
{
"Service": true,
"ZipCode": "02865",
"City": "Lincoln",
"State": "RI",
"plumbing": true,
"electric": true,
"septic": true,
"excavation": true,
"draincleaning": true,
"heating": true,
"cooling": true,
"waterquality": true,
"commercial": true
}
jQuery
if (response.hasOwnProperty("plumbing")){
services.push("Plumbing");
}
if (response.hasOwnProperty("electric")){
services.push("Electric");
}
if (response.hasOwnProperty("septic")){
services.push("Septic");
}
if (response.hasOwnProperty("excavation")){
services.push("Excavation");
}
if (response.hasOwnProperty("draincleaning")){
services.push("Drain Cleaning");
}
if (response.hasOwnProperty("heating")){
services.push("Heating");
}
if (response.hasOwnProperty("cooling")){
services.push("Cooling");
}
if (response.hasOwnProperty("waterquality")){
services.push("Water Quality");
}
if (response.hasOwnProperty("commercial")){
services.push("Commercial");
}
Gives me
["Plumbing", "Electric", "Septic", "Excavation", "Drain Cleaning", "Heating", "Cooling", "Water Quality", "Commercial"