angular 4 - 从对象数组中读取 属性

angular 4 - read property from an array of objects

我想读取数组的每个速率 属性。我不知道是否有任何方法可以从该费率记录中仅调用 $values ??

我这样做是为了调用这个数组:

async ngOnInit() {
    this.product$ = await this.reviewService.getReview(this.product.$key);
    this.key = Object.values(this.product.reviews);
}

因此您可以使用 map 方法获取一组比率,然后使用 reduce,我的意思是:

ngOnInit():void{
    // get an array of rates 
    const rates = yourArray.map(item => item.rate) // rates=[2,3,5,1,..]

    // use reduce function to calculate the sum
    const sum = rates.reduce(this.total)
} 



private total(total,num){
   return total + num
}