I have two Objects that are structured as follows:
export const recipes: Recipe[] = [
new Recipe( id: "Green", scenario: ["1", "2"]),
new Recipe( id: "Blue", scenario: ["1", "2","2"])
];
export const scenarios: Scenario[] = [
new Scenario( id: "1", ...),
new Scenario( id: "2", ...)
];
Within my Recipe model, I have implemented a function to fetch Scenarios based on their id: string
:
getScenario(): Scenario[] {
return scenarios.filter(scenario => this.scenario.includes(scenario.id));
}
This function filters Scenarios based on matching the id: string
.
The issue arises when a property scenario: string[]
contains the same id: string
multiple times. In such cases, it returns an array with ["1", "2"]
instead of ["1", "2","2"]
, which is what I need.