Array Compare issue

Options
i have two array like array[A] and array[B] i want compare both array element are same or not and which element is not present in array

Example
arrA=['hello','hii','ok']
arrB=['hello','hii']
if we are compare this both array than in arrB 'ok' element not inside of arrB
any solution for this???

Comments

  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    Options
    Hi, Im not totally sure what you are trying to answer. 

    Do you want:
    1. a function that returns true when passed arguments of [A,B] and [A,B] but false when passed [A,B] and [A,B,C]? (array compare); or
    2. a function that when passed [A,B] and [A,C,D] will return [B, C, D]? (array diff); or
    3. Something different? From the above?

    With for and while loops, one can make a function that does just about anything with arrays in Xano, but need to understand the inputs and outputs to recommend either a built-in or how you could approach with a custom function.
  • Khan aqib
    Khan aqib Member
    Options
    First option
    Do you have any solution for array compare
  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    Options
    The built-in array_diff function in Xano makes this relatively easy to do. You can ask which elements are in the first array but not in the second, and then ask the question in reverse to get the true/false you are looking for. I made a short video showing how to do this: https://www.loom.com/share/b645e1fb9a21420897c0acd75753e615
  • Khan aqib
    Khan aqib Member
    Options
     thanks