I have this code, which filters my data. I'm asking me, if there is a way not to filter each field (id, mandant, zonenlogik...) explicitly.
Maybe there is a more smooth way to set the filter on all fields without calling them explicitly?
let filteredList = this.state.freights.filter((freight) => {
if (freight.id.toLowerCase().indexOf(this.state.search.toLowerCase()) !== -1) {
return freight;
}
if (freight.mandant.toLowerCase().indexOf(this.state.search.toLowerCase()) !== -1) {
return freight;
}
if (freight.zonenlogik.toLowerCase().indexOf(this.state.search.toLowerCase()) !== -1) {
return freight;
}
if (freight.frachtart_nr.toLowerCase().indexOf(this.state.search.toLowerCase()) !== -1) {
return freight;
}
if (freight.transportart_nr.toLowerCase().indexOf(this.state.search.toLowerCase()) !== -1) {
return freight;
}
if (freight.spedit_nr.toLowerCase().indexOf(this.state.search.toLowerCase()) !== -1) {
return freight;
}
if (freight.spedit2_nr.toLowerCase().indexOf(this.state.search.toLowerCase()) !== -1) {
return freight;
}
if (freight.lager_nr.toLowerCase().indexOf(this.state.search.toLowerCase()) !== -1) {
return freight;
}
});
this.state.search.toLowerCase(). Also, you can group the similar logic with a function.