Reputation: 487
I create a service to get filtered results from a JSON
getItem(id: string): Observable<any[]> {
return this.http.get('path/to/my.json')
.map((response) => {
let results: any = response.json();
let filtered: any = results.filter((result) => {
return result.field === id;
})[0];
return filtered;
}
);
}
Now my Parameter (id) is not a string rather an array. How must i modify my service? Currently, if 'id' is an array, it returns an Array with all Objects from my JSON.
Upvotes: 0
Views: 710
Reputation: 3243
So, assuming it is an array of strings and field should be included in the list you could check that the field is in the list.
ids: string[];
results.filter( (result) => {
return ids.indexOf(result.field) > -1;
})
Upvotes: 1