Name: intersect

Type: command

Syntax: intersect <array> with <templateArray> [<recursively>]

Summary: Removes <element(glossary)|elements> from an <array> if they have no corresponding <element(keyword)> in another <array>.

Introduced: 1.1

OS: mac,windows,linux,ios,android

Platforms: desktop,server,web,mobile

Example:
put "green" into tArray1["color"]
put "left" into tArray1["align"]

put "blue" into tArray2["color"]
put "100" into tArray2["width"]

intersct tArray1 with tArray2

# RESULT
# tArray1[&ldquo;colour&rdquo;] = &ldquo;green&rdquo;

# tArray2[&ldquo;colour&rdquo;] = &ldquo;blue&rdquo;
# tArray2[&ldquo;width&rdquo;] = &ldquo;100&rdquo;

Parameters:
array (array): 
templateArray (array): 
recursively: The recursively adverb indicates that the intersect should recurse through nested arrays.

Description:
Use the <intersect> <command> to filter out <element(glossary)|elements> from an <array> according to the contents of another <array>.

Each key of the <array> is checked to see whether there is a matching <key> in the <templateArray>. The <element(glossary)|elements> of <array> that do not match an <element(keyword)> of the <templateArray> are removed from the <array>.

The content of individual elements of the <templateArray> does not affect the final result. Only which <element(glossary)|elements> exist in the <templateArray>, not their content, controls which <element(glossary)|elements> of the <array> are retained and which are removed. If the <array> and <templateArray> have the same set of <element(glossary)|elements> but different content in each <element(keyword)>, the <intersect> <command> does not change the value of the <array>.

References: split (command), union (command), element (keyword), element (glossary), array (glossary), command (glossary), key (glossary)

Tags: properties
