I have array like this.
[{
id: 1,
name: 'Stephen',
Team: {
name: 'Lion',
color: 'blue'
},
skills: ['allrounder', 'middleorder']
}, {
id: 2,
name: 'Daniel',
Team: {
name: 'Panther',
color: 'green'
},
skills: ['batsman', 'opener']
}, {
id: 3,
name: 'Mark',
Team: {
name: 'Lion',
color: 'blue'
},
skills: ['bowler', 'fielder']
}]
I am providing search facility on every field.
- Name: inputbox
- Team name: dopdownlist (to select team name)
- Team color: dropdownlist (to select team color)
- Skills: checkboxes
User can provide only Name field and click on Search , or can use multiple options like only skills or combination of any of input.
What is best way to filter an array based on these conditions.
e.g.
myArr.filter(item => item.Name.toLowerCase().startsWith(searchData.name.toLowerCase())
&& / || item.skills.include(searchData.skillsArr)
Expected output is based on any single or combination of input provided.