# Array filter

{% hint style="info" %}
To enable **advanced array filtering code** for your multiple choice question, import the library as described in the [getting-started](https://synoint.gitbook.io/survey-library/getting-started "mention") section.
{% endhint %}

Once you have completed the main steps, you will need to modify the parameters in the provided template snippet to apply the changes.

<table><thead><tr><th>Variable</th><th>Example</th></tr></thead><tbody><tr><td><strong><code>question_code</code></strong><br><br>The code of the multiple choice question you want to configure</td><td><pre class="language-javascript"><code class="lang-javascript">multiple_choice({
<strong>    question_code: "Q1"
</strong>});
</code></pre></td></tr><tr><td><strong><code>schema</code></strong><br> <br>This variable represents an <mark style="color:blue;"><strong>open text field</strong></mark> where answer  codes will be stored. It is only required if you plan to use this question to <mark style="color:red;"><strong>filter</strong></mark> or <mark style="color:red;"><strong>randomize in the same order</strong></mark>. Remove it if not needed.<br><br><span data-gb-custom-inline data-tag="emoji" data-code="1f4a1">💡</span>Use a descriptive name for the schema that indicates  it is associated with a specific question code, such as <code>Q1_SCHEMA</code> or <code>Q1xSCHEMA</code><br><br><span data-gb-custom-inline data-tag="emoji" data-code="2139">ℹ️</span> <em>The open text should be placed in the same page of the multiple choice.</em><br><br><img src="https://3256950692-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8ViByLqKSYWJoXIHUUnY%2Fuploads%2F3e3ClosuOgnE57zgEGh1%2Fimage.png?alt=media&#x26;token=a138db89-fc20-45ee-bae0-891477657d21" alt=""></td><td><pre class="language-javascript"><code class="lang-javascript">multiple_choice({
    question_code: "Q1",
<strong>    schema: "Q1xSCHEMA"
</strong>});
</code></pre></td></tr><tr><td><strong><code>array_filter</code></strong><br><br>Here we define the settings for array filter. If not needed, just remove this entire block code and skip this tutorial <span data-gb-custom-inline data-tag="emoji" data-code="1f44d">👍</span></td><td><pre class="language-javascript"><code class="lang-javascript">multiple_choice({
    question_code: "Q1",
    schema: "Q1xSCHEMA",
    /* Other settings */
<strong>    array_filter: {
</strong><strong>        
</strong><strong>    }
</strong>});
</code></pre></td></tr><tr><td><strong><code>array_filter</code></strong> -> <strong><code>filter</code></strong><br><br>This variable allows you to the take into account the answer options that were selected in the filter question code to apply the filter process </td><td><pre class="language-javascript"><code class="lang-javascript">multiple_choice({
    question_code: "Q1",
    schema: "Q1xSCHEMA",
    /* Other settings */
    array_filter: {
<strong>        filter: "Q0"
</strong>    }
});
</code></pre></td></tr><tr><td><p><strong><code>array_filter</code></strong> -> <strong><code>filter_schema</code></strong><br><br>This variable gets the filter's schema that was placed in an <mark style="color:blue;"><strong>open text field</strong></mark>.</p><p></p><p><span data-gb-custom-inline data-tag="emoji" data-code="2139">ℹ️</span> <em>This is required in order to filter only answer codes that appeared in the filter question. Any remaining code outside filter schema will not be filtered.</em><br></p></td><td><pre class="language-javascript"><code class="lang-javascript">multiple_choice({
    question_code: "Q1",
    schema: "Q1xSCHEMA",
    /* Other settings */
    array_filter: {
        filter: "Q0",
<strong>        filter_schema: "Q0xSCHEMA"
</strong>    }
});
</code></pre></td></tr><tr><td><strong><code>array_filter</code></strong> -> <strong><code>type</code></strong><br><br>Variable that defines the behavior of the filter process.<br><br>If <mark style="color:blue;"><strong>inclusive</strong></mark>, the filter will <strong>keep</strong> only answer codes that were <strong>selected in filter question</strong> and are <strong>listed in filter's schema</strong>.<br><br>If <mark style="color:red;"><strong>exclusive</strong></mark>, the filter will <strong>remove</strong> only answer codes that were <strong>selected in filter question</strong> and are <strong>listed in filter's schema</strong>.</td><td><pre class="language-javascript"><code class="lang-javascript">multiple_choice({
    question_code: "Q1",
    schema: "Q1xSCHEMA",
    /* Other settings */
    array_filter: {
        filter: "Q0",
        filter_schema: "Q0xSCHEMA",
<strong>        type: "inclusive"
</strong>    }
});
</code></pre></td></tr></tbody></table>
