arraydifference
ARRAYONE
,
ARRAYTWO
,
SEPARATOR
,
ARRAYUNIQUE

The arraydifference statement creates a new array from two existing arrays. The new array contains only items that are in the first array but not in the second array.

Parameters

This statement has four parameters:

arrayone – the first array.

arraytwo – the second array.

separator – the separator character or characters. Both of the original arrays must use this separator, and the output array will also use this separator.

arrayunique – the new array that contains all elements that are in arrayone but not in arraytwo.

Description

The Arraydifference statement creates a new array from two existing arrays. The new array contains only items that are in the first array but not the second array. The output array will be sorted alphabetically. Empty array elements, if any, will not be included in the output array, even if the first array contains empty elements and the second array doesn’t.

This example figures out which colors Jack likes, which Jill likes, and which they both like.

``````local jackLikes,jillLikes,bothLike,onlyJackLikes,onlyJillLikes
jackLikes = "red,green,orange,blue,white"
jillLikes = "black,white,red,blue"
arrayboth jackLikes,jillLikes,",",bothLike
arraydifference jackLikes,jillLikes,",",onlyJackLikes
arraydifference jillLikes,jackLikes,",",onlyJillLikes
message "Jack likes "+commalist(onlyJackLikes,",")+
"; Jill likes "+commalist(onlyJillLikes,"")+
"; and they both like "+commalist(bothLike,",")
``````

The message will display:

``````Jack likes green and orange; Jill likes black; and they both like blue,red and white
``````

See Text Arrays for more information about arrays. Note: This operation can also be done in a formula using the arraydifference( function.