I'm using Node.js with Express for a back-end server. I am sending in some data as a json and after parsing it I'm trying to iterate through the object so I can assign values. For a test I'm passing in an object that has 50 objects in it.
I've tried using for in loop with hasOwnProperty but it has never completed all of them.
for (i in req.body.deviceObject) {
if (req.body.deviceObject.hasOwnProperty.call(req.body.deviceObject[i].dId, i)) {
newVcsObject[i] = new PQ(
'insert into VCS(ip_address, vcs_name, user_name, user_password, ID) values ($1, $2, $3, $4, $5)'
);
newVcsObject[i].values = [
req.body.deviceObject[i].ipAddress,
req.body.customerName,
req.body.deviceObject[i].uName,
req.body.deviceObject[i].uPassword,
req.body.deviceObject[i].VCSID
];
console.log(i);
count += 1;
}
}
edit: this is my data structure:
"deviceObject": {
"1": {
"rId": "e43aebb5-234f-4aa6-a666-90179df767bc",
"e164": "449bc7cc-90fa-4b9e-b4c1-1223d825d545",
"uName": "Server",
"uPassword": "admin",
"VCSID": "54191576-47ea-4055-8ea4-bc201dc54f6d",
"ipAddress": "1.1.1.1",
"dId": "b6178041-86cc-4959-9155-54ca419083e7"
},
//there are more in between, this is where it's stuck
"35": {
"rId": "dce82b00-fa1e-46b8-a3f6-1a5af45175de",
"e164": "7cc8190b-c261-40f8-9f62-408f7e8b2450",
"uName": "access point",
"uPassword": "admin",
"VCSID": "3e3e447c-b9fe-4997-ba54-225175b0a84b",
"ipAddress": "1.1.1.1",
"dId": "9c97d5a5-b26f-492e-ba5b-bdd33eb3cb30"
}
// goes all the way to 50
I always go through 35/50 of the input. I have double checked and the server is receiving all 50 of them without a problem, but it only iterates through the first 35.