OK here's the deal: I've got a simple filter component acting on a returned API set. Each returned item has an array of properties, and I want the formula to filter by checking to see if any of the properties in the array match the currently selected variable. Thinking this should be a find action, returning true if any of the items in the array are a match, which then filters the set? I thought this would be easy but I can't figure it out 😄
Max
4 days ago
Do you have an example of your data structure (JSON) and your filter condition?
Filip Dajkovic
4 days ago
You shouldn't use Find formula (action) for that, it just returns the first matching item, you'll need the Filter formula which returns a new array containing only items which returned true
Thanks Max! JSON returns an array of objects; there are also a few other arrays, which is what I'm trying to get to. So like: data[0][films[0]] (Not sure I got the syntax right, but each item in the data array contain arrays, and within a secondary array films is a list of URLs. I'm trying to match against one of those URLs. The filters are buttons which update a variable with a URL, so the task is to see which of the returned arrays contain the film URL matching the selected button. Does that make sense?
Ohhh OK! Thanks. I was thinking I could use Find to loop through each item see if the matched URL was present, then set a condition to true, but it seems that doesn't work.
Max
1 day ago
Hi! I am still not sure what you want to have as a result. Would be helpful to see an actual dataset and what your result should be. I attached an example that filters the first level. So If data[x].films contains a certain value, data[x] is included in the results. Not sure if that is what you are trying to achieve
Oh, I see now, you should use either the "Includes" formula as Max suggested it, or "Some" formula if the url you're looking for is nested and harder to get to, in that case, if one of these formulas returns true, the item would pass the filter