How to find the difference between two arrays?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By JulioYagami

How to find the difference between two arrays?

# For example:
arr1 - arr2 = arr3

What do you define as the “difference” of two arrays?

Zylann | 2019-09-16 21:29

For example:

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

JulioYagami | 2019-09-17 10:50

:bust_in_silhouette: Reply From: Zylann

You could try this function:

func difference(arr1, arr2):
	var only_in_arr1 = []
	for v in arr1:
		if not (v in arr2):
			only_in_arr1.append(v)
	return only_in_arr1