I have a target array example: ["Potato", "Orange"] . I'm making an api call that return an object with multiple array which I have to look if the array contain any one of the target array elements.
I have the following Piece of code, but I get following error : Uncaught TypeError: Cannot read property 'includes' of null
I know this is because The object contains some Null values. How Can I fix this?
Example: const myArray = [
{
Track: ["Potato", "Apple"],
["Banna"],
["Potato", "Batman", "Orange"]
Type: ["Some", "Stuff"]
},
{
Track: null
Type: ["Some", "Stuff"]
}
]
const value = "Potato"
const matchingSession = myArray.filter((obj) => value.some(x => { return obj.types.includes(x) || obj.tracks.includes(x)}));
Which it should Return :
[
["Potato", "Apple"],
["Potato", "Batman", "Orange"]
]
This is just an example. It could have more then one object in the array.
types(nortracks). Your input also isn't valid Javascript, arrays cannot have key-value pairs