I am new to JavaScript, tried below code and not able to get it. I have gone through many other post but didn't work.
Output: Check if AUTO damage is present. If Yes, get count and display First & Last for the same.
var myObj, i, x = "";
myObj = {
"Initial": {
"claim": [{
"first": "abc",
"last": "xyz",
"damage": {
"auto": true,
"manual": true
}
}, {
"first": "mne",
"last": "odc",
"damage": {
"manual": true
}
}, {
"first": "svc",
"last": "tre",
"damage": {
"auto": true
}
}, {
"first": "tre",
"last": "hdf",
"damage": {}
}]
}
}
var myObj = myObj.Initial.claim;
console.log(myObj);
for (i = 0; i < myObj.length; i++) {
x += myObj.first[i] + "<br>";
x += myObj.damage.auto[i] + "<br>";
}
document.getElementById("demo").innerHTML = x;
<p id="demo"></p>