I have the scenario, with provided example JSON data:
[{
"name": "Joe",
"age": "28",
"hobby": ["Reading", "Chilling", "Cycling"]
},
{
"name": "Beck",
"age": "25",
"hobby": ["Drinking", "Cycling"]
},
{
"name": "Candace",
"age": "24",
"hobby": ["Reading", "Singing"]
}]
Let's say the array above are shown in some list in web page.
I have 2 (two) search dropdown with multiple selection to search name and age.
- For name, let's say it shows all distinct hobbies (Reading, Chilling, Cycling, Drinking, Singing).
- For age, let's say it have 2 options for age range: 23-26 and > 27.
For searching hobby, my code is (in ReactJS):
filteredPersons = this.state.personList.filter( person =>{
return person.hobby.some(v=> filterHobby.indexOf(v) !== -1)
});
which is:
personListis list of array from JSON above;filterHobbyis list of array from multiple select, ex: iffilterHobby = ["Reading","Singing"], it will show Joe and Candace.
The question is, how can I search for age with multiple selection?
Expected result:
- Choose
23-26only will show Beck and Candace - Choose
>27only will show Joe - Choose both will show Beck, Candace and Joe
Thank you for any answer.
filterHobby.