I can't understand the reason of using [0]
in front of dish.id and dish.featured
in the following code:
import { Injectable } from '@angular/core';
import { Dish } from '../shared/dish';
import { DISHES } from '../shared/dishes';
@Injectable()
export class DishService {
constructor() { }
getDishes(): Dish[] {
return DISHES;
}
getDish(id: number): Dish {
return DISHES.filter((dish) => (dish.id === id))[0];
}
getFeaturedDish(): Dish {
return DISHES.filter((dish) => dish.featured)[0];
}
}
This is the Dish
class:
import { Comment } from './comment';
export class Dish {
id: number;
name: string;
image: string;
category: string;
label: string;
price: string;
featured: boolean;
description: string;
comments: Comment[];
}