This is part of a JSON data I'm trying to make an array of and put them in a Google Spreadsheet,
This is the m part
"m":{
"414" : {"a":123},
"47279":{"a":1234 },
"463306":{"a":12345}}
This is the z part
"z":{"3270":
"414" : {"d":{"0":{"p":500}}},
"47279":{"d":{"0":{"p":700}}}}
This is the JS code I'm Using
var Uid = Object.getOwnPropertyNames(doc1.m);
for (var lp2 = 0; lp2 < Uid.length; lp2++) {
var Uid1 = Uid[lp2];
var TotalD = Math.round(doc1.m[Uid[lp2]].a);
testUF.push([Uid1, TotalD]);
}
//Total Obelisk Defense
for (var lp1 = 0; lp1 < testUF.length; lp1++) {
var lp35id = Object.getOwnPropertyNames(doc1.z["3270"]).length;
var ob35id = Object.getOwnPropertyNames(doc1.z["3270"]);
var ob35 = "3270";
for (var lp3 = 0; lp3 < lp35id; lp3++) {
if (ob35id[lp3] === testUF[lp1][0]) {
if (typeof doc1.z[ob35][ob35id[lp3]] !== 'undefined' && doc1.z[ob35][ob35id[lp3]] !== null && doc1.z[ob35][ob35id[lp3]] !== "") {
var ob35D = (doc1.z[ob35][ob35id[lp3]].d["0"].p);
} else {
var ob35D = "0";
}
}
var ob35TD = ob35D;
}
var obTD = ob35TD;
testUF[lp1][2] = Math.round(obTD);
}
The Result I'm Getting
+--------+--------+------+
| Uid1 | TotalD | obTD |
+--------+--------+------+
| 414 | 123 | 500 |
+--------+--------+------+
| 42729 | 1234 | 700 |
+--------+--------+------+
| 463306 | 12345 | 700 | <<-- This is the Problem, The obTD Value should be 0
+--------+--------+------+
So the problem is in my result you can see the obTD value just duplicates from the previous value when the Uid does not exist in the "m" object, but I want it to be 0 if the Uid doesn't exist in the "z":{"3270" object.