Help forum

Looping through an array and comparing against another array.

  • Bazza

    1 year ago

    I am building a search page with filters.

    Our sites have various facilities, I want our users to be able to filter based on these facilities. When they click the facility in the filter, it gets added to the selectedFacilities array.

    In my formula I'm trying to compare this array with each sites facilities (Also an array). The site facilities array is passed into this formula.

    If any of their selected facilities are in the site facilities array, it should return true (That gets passed out to a bigger filter formula)

    I cannot get this to work at all, any help looping through arrays would be greatly appreciated.
    1376365452732923904-image.png
    ✅1
  • Bazza

    1 year ago

    That every statement is just returning true, I would expect it to return the item value.
  • Andreas Møller

    1 year ago

    I think you want it the other way around

    Try swapping every and includes
  • Bazza

    1 year ago

    I've tried that way too. Tried just about everything I can think of but there isn't any real way to compare two lists. I may have to rethink how the filter works.
  • Andreas Møller

    1 year ago

    Ah I mis ready your question. If you need to check if ANY of the items is present you need to use "Some" instead of Every
  • Every checks if a condition is true for ALL items
  • Andreas Møller

    1 year ago

    1376475572796129380-CleanShot_2025-05-26_at_10.22.132x.png
  • Bazza

    1 year ago

    You were right first time, Every was what I needed. Now working, thank you 💪
  • Andreas Møller

    1 year ago

    Great!
  • Glad I could help
  • lauri5807

    1 year ago

    Hey, I have similar problem and can't wrap my head around it.

    I have two APIs
    1. Guests (all the guest with their names, and "Group" which includes all tags split with commas (e.g. "Friday, Saturday, LauriKokkila")
    2. Schedule (called here Aikataulu) that has events and each event has "Groups" that defines what people should be attending this one, again split with commas (e.g. "LauriKokkila, IlpoKokkila")

    How do I create that for the current Guest (recognised from URL), show all events where any of their "Group" value is one of the "Groups" value in the schedule?
  • 1398731135902552085-image.png
  • Andreas Møller

    1 year ago

    Some returns true or false. You are looking for filter
  • Andreas Møller

    1 year ago

    Other than that you are on the right track, but since the users group property is also a comma separated list you need to split that as well
  • Andreas Møller

    1 year ago

    That is probably the best I can do to explaining while I’m on mobile 🙂


    try copying the whole function to Claude and see if it understands:)
  • lauri5807

    1 year ago

    Tried with o4 but ofc Clauded done it immediately 🙂 thanks Andreas!!
  • Andreas Møller

    1 year ago

    This is coming natively to Nordcraft in the not too distant future 🙂