Hi! I’m trying to find the best way to filter a json file. Here’s the json:
var data = {
laureates: [
{
id: "1",
firstname: "Wilhelm Conrad",
surname: "R\u00f6ntgen",
born: "1845-03-27",
died: "1923-02-10",
bornCountry: "Prussia (now Germany)",
bornCountryCode: "DE",
bornCity: "Lennep (now Remscheid)",
diedCountry: "Germany",
diedCountryCode: "DE",
diedCity: "Munich",
gender: "male",
prizes: [
{
year: "1901",
category: "physics",
share: "1",
motivation:
'"in recognition of the extraordinary services he has rendered by the discovery of the remarkable rays subsequently named after him"',
affiliations: [
{ name: "Munich University", city: "Munich", country: "Germany" }
]
}
]
},
{
id: "2",
...
...
I need to apply multiple filters to return only data I need. I can filter by category, year from, year until, gender, countryDied. All the filters are optional, so if a user doesn’t specify anything, it returns the full data.
What would be the best/elegant approach to this? I tried with .filter() functions, but it seems that there could be a much better way to do this.