0 votes

How to find the difference between two arrays?

# For example:
arr1 - arr2 = arr3
in Engine by (692 points)

What do you define as the "difference" of two arrays?

For example:

["value1", "value2", "value3"] - ["value2"] = ["value1", "value3"]

1 Answer

+2 votes
Best answer

You could try this function:

func difference(arr1, arr2):
    var only_in_arr1 = []
    for v in arr1:
        if not (v in arr2):
    return only_in_arr1
by (29,090 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.