Reputation: 761
I have a list of array. Avery array has an object, and I want to get the value of this object
My code as follow:
var data =[]
var children= response.data.children
children.forEach(function (child) {
if(equipes.hasOwnProperty(child['id'])) {
total += equipes[child['id']];
dataequipes.push({
id: child['id'],
total: equipes[child['id']]
});
}
});
series.domain = domainId;
series.total = total;
series.details = dataequipes;
data.push(series);
return data;
In my other function I call the returned value and the result as follows:
But when I want to call the total value of object, I got always error:
I used data.total, data['total']
... but without any result
Upvotes: 0
Views: 78
Reputation: 6746
You can try something like this;
let total = 0;
data.forEach(function (item) {
if(item.hasOwnProperty('total')) {
total = item.total
}
});
Upvotes: 1