Page tree

 

Support | BlogContact Us | 844.332.2821

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin

D toc

Excerpt

Combines one array containing keys and another array containing values into an Object of key-value pairs.

  • This function applies to two inputs only. 
  • Inputs can be array literals, column references, or functions returning arrays.

 If the number of key elements is greater than the number of value elements, null values are generated for the missing values in the output Object. If the number of value elements is greater, the DEFAULT_KEY value (third parameter) is applied.

D s
snippetBasic

Array literal reference example:

D code

derive value:ARRAYSTOMAP(["A","B"],["1","2","3"] ) as:'myMap'

Output: Generates an Object associating keys from the first array with values from the second array.

Column reference example:

D code

derive value:ARRAYSTOMAP(array1,array2, 'extraProps') as:'array2mapped'

Output: Generates a new array2mapped column containing an Object pairing the elements of the arrays as key-value pairs. Any extra values in array2 are assigned to the extraProps key.

Function reference example:

D code

derive value:ARRAYSTOMAP(array1,concat([array2,array3])) as:'array2map'

Output: Generates a new array2map column containing an Object pairing the elements of array1 and the array created by concatenating array2 and array3.

D s
snippetSyntax

D code

derive value:ARRAYSTOMAP(array_keys,array_values, ['DEFAULT KEY'])

ArgumentRequired?Data TypeDescription
array_keysYstring or arrayName of column, array literal, or function returning an array whose elements are the keys for the generated Object
array_valuesYstring or arrayName of column, array literal, or function returning an array whose elements are the values for the generated Object
DEFAULT_KEYNstring literalAny extra values are assigned to this specified key

d-s-lang-notes

array_keys

Name of the array column, array literal, or function returning an array whose elements you want to use as the keys for the Object.

D s
snippetusage

Required?Data TypeExample Value
YesString (column reference, function returning an array) or array literalmyKeys

array_values

Name of the array column, array literal, or function returning an array whose elements you want to use as the values in the Object.

D s
snippetusage

Required?Data TypeExample Value
YesString (column reference, function returning an array) or array literalmyValues

DEFAULT KEY

If there are extra elements in the second array, they are assigned to the key that is defined by this parameter.

D s
snippetusage

Required?Data TypeExample Value
NoString literal'extraProperties'

D s
snippetExamples

Example - Create an Object of product properties

Include Page
EXAMPLE - ARRAYSTOMAP Function
EXAMPLE - ARRAYSTOMAP Function

D s also
labelnested