Sometimes it's convenient to combine multiple individual elements — numbers, texts, variables — into a single collection called an array. Arrays can be used to:
- Extract individual elements by their index
- Display the whole array to the respondent, with elements separated by commas
- Compare to another array to check if they match
- Search an array for an exact value (e.g. find if a respondent said "agree" or "yes" in any of their open-ended responses)
- Search an array for partial text (e.g. check if a respondent mentioned a brand, given an array of possible misspellings)
Syntax
-
[ar << 1]— create array with number 1, or add 1 to an existing array -
[ar << 1,2,3,4]— create array with numbers 1, 2, 3, 4 -
[ar_1 << "first", "second", "third"]— create array with text values -
[v4 << '0', 1, 2, 3]— mixed types are supported -
[ar3|3]— pipe in the third item from ar3 -
[ar3]— pipe the whole array, comma-delimited -
[ar4|3 + 1]— add 1 to the third item in ar4 -
[show if ar4|501 = 7]— show if the 501st item in ar4 equals 7 -
[show if ar3 = ar4]— show if arrays are equal (order matters) -
[show if "first" in ar_1]— show if there's at least one "first" in ar_1 -
[show if "st" like ar_1]— show if there's at least one text containing "st" in ar_1
Examples
- You asked respondents where their most exciting vacation took place in an open-ended question. If the respondent mentioned a variation of the US country name, you want to show additional questions. At the beginning of the survey, declare:
[usvariants<<"US","U.S.","United States","USA","U.S.A.","United States of America"]. Then use it to conditionally show questions:[show if Q5RC like usvariants]. - During a survey you assign respondents labels like "early bird" or "influencer". Instead of individual variables for each label, use an array named
labels. When a respondent qualifies, add the label:[labels<<"influencer"]. Then at Q10:[show if "early bird" in labels], and at Q11:[show if "influencer" in labels].
Shuffle
Randomly redistribute the positions of elements in an array. The optional max modifier limits the result to a specified number of elements.
-
[scores_array<<1,2,3,4,5] [scores_array = shuffle scores_array]— shuffle first five natural numbers -
[scores_array = shuffle scores_array]— shuffle scores_array in place -
[arr2 = shuffle arr1]— shuffle arr1 and save into arr2 -
[scores_array<<1,2,3,4,5] [scores_array = shuffle scores_array max 2]— shuffle and save only two elements -
[scores_array = shuffle scores_array max 2]— shuffle and keep only two elements
Reverse
Reverse the order of an array — the last element moves to the first position, the second-last to second, and so on.
-
[scores_reversed = reverse scores]— reverse the scores array and store in scores_reversed
Unique
Remove all duplicates from an array, ensuring each element appears only once in the result.
-
[scores_unique = unique scores]— store only unique elements from scores into scores_unique
Sort
Sort an array in ascending order. Behavior depends on the array type:
- Numerical arrays: ascending numeric order — 1 < 10 < 11 < 100
- Character arrays: numerals precede letters, capitals precede lowercase — "1" < "10" < "100" < "11" < "Apples" < "apples"
-
[scores_sorted = sort scores]— sort and store in scores_sorted -
[scores_sorted_descending = reverse sort scores]— sort in descending order
Sort Elements by Array
Use an array of one-based indices to impose a specific display order for elements in the survey. Logic placement doesn't matter — it can be placed on any question, as long as the variable is initialized before the sorted question.
💡 Tip: For alphabetical sorting, see the simpler sort elements a-z approach.
-
[CustomOrder << 4, 3, 2, 1][sort q2a by CustomOrder]— show Q2's four elements in reversed order (4 means element 1 goes to position 4) -
[CustomOrder << 4, 3, 2, 1][sort q2a by CustomOrder if gender='m']— reversed order for male respondents only; females see the original order -
[CustomOrder << 4, 3, 2, 1][sort q2sq by CustomOrder]— reversed order for subquestions in Q2 -
[CustomOrder << 1, 2, 3, 4] [CustomOrder=shuffle CustomOrder] [sort q2a by CustomOrder] [sort q3a by CustomOrder]— randomize order and apply the same order to both Q2 and Q3