嗨,大家好,我是新手,请帮助我如何访问对象内部的值。我想访问此数组中的SuccessCount
这是我的尝试
goodResponse=[
{compId: 1, companyName: "A", pendingCount: 0, successCount: 0, apiErrorCount: 0, …}
{compId: 1, companyName: "B", pendingCount: 0, successCount: 0, apiErrorCount: 0, …}
{compId: 3, companyName: "C", pendingCount: 0, successCount: 0, apiErrorCount: 0, …}
{compId: 4, companyName: "D", pendingCount: 0, successCount: 0, apiErrorCount: 0, …}
]
let _graphTotal = this.goodResponse;
let _graphTotalCount = []
_graphTotal.forEach(element => {
console.log("total Count", element[0].successCount)
});
答案 0 :(得分:0)
由于要遍历数组goodResponse,因此需要访问该对象,因此它应该类似于
_graphTotal.forEach(element => {
console.log("total Count", element.successCount)
});
答案 1 :(得分:0)
您需要访问当前元素的successCount
,而不是尝试访问successCount不存在的元素。
_graphTotal.forEach(element => {
console.log("total Count", element.successCount)
});
答案 2 :(得分:0)
将element[0].successCount
替换为element.successCount
。
答案 3 :(得分:0)
map中的每个元素都返回一个对象。因此map返回的第一个元素将是数组的第0个索引。现在,您有一个对象作为您的第一个元素,并且需要使用dot(。)来访问该对象内部。这样函数就变成了element.successCount
答案 4 :(得分:0)
使用ForEach循环运行时,每个“元素”都是数组中的数据,因此您需要编写:
element.successCount