var temp = [];
//this loop pushes 4 elements in the array for each element in resultDb
for(var i in resultDb){
temp.push({'ID':resultDb[i].ID});
temp.push({'Label':resultDb[i].Label});
//why an array here?
temp.push({'User':[{'Name':resultDb[i].Name , 'ScreenName':resultDb[i].ScreenName}]});
temp.push({'TDate':resultDb[i].TDate});
}
//...therefore you have resultDb.length * 4 elements in temp.
//and only 1 every 4 elements has a User property
for(var i in temp){
console.log(temp[i].User.ScreenName);
}
:
var temp = [];
for(var i in resultDb){
temp.push(Object.assign(
{'ID':resultDb[i].ID},
{'Label':resultDb[i].Label},
{'User':{'Name':resultDb[i].Name, 'ScreenName':resultDb[i].ScreenName}},
{'TDate':resultDb[i].TDate}
));
}
for(var i in temp){
console.log(temp[i].User.ScreenName);
}
はここでそれを行うのにも良い方法です:
var temp = resultDb.map(function (result) {
return Object.assign(
{'ID':result.ID},
{'Label':result.Label},
{'User':{'Name':result.Name, 'ScreenName':result.ScreenName}},
{'TDate':result.TDate}
);
})
for(var i in temp){
console.log(temp[i].User.ScreenName);
}
は 'User'は配列です。 [mcve]を提供してください –