I have an array of object, were objects can have optional name value, or subject value.
Also a have filterString.
I have to write filter function, which ckecks if one of this values include this string.
const filterString = e.target.value.toLowerCase();
if (filterString != "") {
let filteredItemsList = this.state.itemsList.filter(
el =>
el.subject
.toLocaleLowerCase()
.includes(e.target.value.toLocaleLowerCase()) ||
el.name
.toLocaleLowerCase()
.includes(e.target.value.toLocaleLowerCase())
);
this.setState({
itemsList: filteredItemsList,
filter: e.target.value.toLocaleLowerCase()
});
This is what i have now. I get error like Cannot read property "toLocaleLowerCase" of undefined, because my element have name OR subject, how i can avoid this ?