How can I update this snippet to use Object.keys()? It currently works well when the comment ids are numbers, but how can it be adapted to work with auto-generated ids from Firebase?
(The data structure is provided below)
ngOnInit() {
this.route.params
.pipe(switchMap((params: Params) => this.dishservice.getDish(params['id'])))
.subscribe(dish => {
this.dish = dish;
this.favorite = this.favoriteService.isFavorite(this.dish.id);
// Calculate the average of ratings and display the number of comments
this.numcomments = this.dish.comments.length;
let total = 0;
this.dish.comments.forEach(comment => total += comment.rating);
this.avgstars = (total / this.numcomments).toFixed(2);
},
errmess => this.errMess = errmess);
}