arrayUtils

Description:
  • Set of utils for working with array in SFCC.
Source:
Set of utils for working with array in SFCC.

Methods

(inner) difference(primaryArray, …arraysToCompare) → {array}

Description:
  • Finds the difference between an array and one or more arrays.
Source:
Example
difference(['DE', 'CZ', 'GB', 'DK'], ['DE', 'BE'], ['DK', 'NL', 'EE']);
['CZ', 'GB']
Parameters:
Name Type Attributes Description
primaryArray array The primary array to compare.
arraysToCompare array <repeatable>
One or more arrays to compare with the primary array.
Returns:
An array containing the values that are present in the primary array but not in any of the arrays to compare.
Type
array

(inner) flatten(arrays) → {array}

Description:
  • Flattens an array of arrays into a single-dimensional array.
Source:
Example
flatten([['DE', 'CZ'], 'US', ['BE'], ['DK', 'NL']]);
['DE', 'CZ', 'US', 'BE', 'DK', 'NL']
Parameters:
Name Type Description
arrays array The array of arrays to flatten.
Returns:
The flattened array.
Type
array

(inner) unique(callbackopt) → {array}

Description:
  • Returns an array of unique values based on the provided array. If a callback function is provided, it is applied to each element of the array to determine uniqueness based on the transformed values.
Source:
Example
unique(['DE', 'BE', 'DE', 'CZ', 'NL', 'DK', 'NL', 'EE']);
// [ 'DE', 'BE', 'CZ', 'NL', 'DK', 'EE' ]

unique(['DE', 'BE', 'DE', 'CZ', 'NL', 'DK', 'NL', 'EE'], item => item[0]);
// [ 'DE', 'BE', 'CZ', 'NL', 'EE' ]
Parameters:
Name Type Attributes Description
array The input array.
callback function <optional>
A callback function applied to each element of the array. It should return a value used for uniqueness comparison.
Returns:
An array containing unique values based on the provided array.
Type
array