I have an object that I want to filter based on whether or not a nested array contains a certain value.
Data
{
"content": [
{
"text" : "#number# Tips to Get #solution#",
"types" : [ "email"]
},
{
"text" : "Want #desiredResult#? Use #productName#",
"types" : [ "ad", "email" ]
},
{
"text" : "Your Search For #solution# Ends Here",
"types" : [ "ad", "email" ]
}
]
}
Now I want to return a new array based on whether a specific value is present. E.g. if I were to filter by ad, only the last 2 entries would be returned:
Filtered by ad
{
"content": [
{
"text" : "Want #desiredResult#? Use #productName#",
"types" : [ "ad", "email" ]
},
{
"text" : "Your Search For #solution# Ends Here",
"types" : [ "ad", "email" ]
}
]
}
I initially thought I could use Array.prototype.filter(), but I haven't been able to get that to work. Which I assume is because the array is nested, but I'm unsure on how to reach it.
How would I filter to return only those entries where the type matches a filtered value?
jsontag (or term) for JavaScript object literals.