I have an array of objects and within those objects there is a nested object with an array that i am trying to evaluate. It looks something like this:
item = [
{firstName: "John"
lastName: "Johnson"
capabilities: {demographic: Array(3), geographic: Array(3), language: Array(2)}
id: "ndja1-234-njk"
state: LA
}
{firstName: "Jane"
lastName: "Johnson"
capabilities: {demographic: Array(3), geographic: Array(3), language: Array(2)}
id: "ndsa1-234-njk"
state: TX
}
]
I am trying to filter the list of objects and only return the objects which match the users input for either firstname, lastname, phonenumber, and geographic. But because the geographic is not at the first level of the array I am getting an error that says is is null when i try and filter through it like this:
const newList = (items, value) => {
let providerList = items.filter(i => i.firstName.includes(value) || i.lastName.includes(value) || i.phone.includes(value) || i.capabilites.geographic.includes(value));
setSearchResult(providerList)
};
I believe it is because of the position of the geographic values in the object but im not sure how to handle waiting for it to not be null. This function works until I add the geographic OR statement.
includesfor checking a string? As'hello'.includes('o')is true.includes? I realize now this is not the best logic for this