Object.keys
HTML
<div id="divname" style="width: 350px; height: 100px;border:1px solid ;">
<p id="divname1"> </p>
</div>
JavaScript
var obj = {
"Response": {
"Errors": {
"Check": {
"ReportingCategoryLabel": [
"Line No 4 Missing Category Report",
"Line No 4 Missing Category Report 1",
"Line No 4 Missing Category Report 2",
"Line No 4 Missing Category Report 3",
"Line No 4 Missing Category Report 4"
],
"_id": "223",
"_name": "error1234"
}
},
"Success": {
"Check": {
"_id": "223",
"_name": "success1234"
}
}
}
}
function iterObj(obj) {
var docu = document.getElementById("divname1");
var br = document.createElement("br");
for (var key in obj) {
console.log(key + ': ' + obj[key]);
"<br />"
docu.innerHTML = key + "<br />" + obj[key] +"\n";
if (obj[key] !== null && typeof obj[key] === "object") {
iterObj(obj[key]);
}
}
}
iterObj(obj);
Object.keys(obj).forEach(function(key) {
console.log('Key : ' + key + ', Value : ' + obj[key])
})