I want to get sum of the values in array. With this code when I console.log(this.totalCount) I only get like this
.
How to get sum of all the values?
CODE
return this.http
.post('/media', reqBody)
.pipe(
map((res:IStatisticReponse) => res.data)
).subscribe(res => {
this.items = res.map((r: any, i: number) => {
r.color = this.colors[i]
return r;
});
this.legendProgress = this.items.map(item => {
return { label: item.label, color: item.color };
});
this.totalCount = this.items.map((item)=> item.mediaShare);
console.log(this.totalCount)
this.isLoading = false;
});
this.totalCount.lengtheven I not sure why you are using map with empty valuethis.items.lengthI got error(property) Array<any>.length: number Gets or sets the length of the array. This is a number one higher than the highest element defined in an array. This expression is not callable. Type 'Number' has no call signatures.ts(2349)console.log(this.items)?sumof those value