0 votes

How to find the difference between two arrays?

# For example:
arr1 - arr2 = arr3
asked Sep 16, 2019 in Engine by JulioYagami (637 points)

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

For example:

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

1 Answer

+1 vote
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
answered Sep 17, 2019 by Zylann (26,967 points)
selected Sep 18, 2019 by JulioYagami
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 How to use this Q&A? before posting your first questions.