- Description:
- Set of utils for working with collections in SFCC.
- Source:
Set of utils for working with collections in SFCC.
Methods
(inner) filter(collection, callback) → {array}
- Description:
- Creates a new array containing only items from the collection that pass the test implemented by the provided callback function.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
collection |
dw.util.Collection | The collection to filter. |
callback |
function | The callback function to be called for each item. Takes two arguments: the current item and its index. Returns true to keep the item, false to exclude it. |
Returns:
A new array containing the filtered items.
- Type
- array
(inner) forEach(collection, callback) → {void}
- Description:
- Iterates over each item in the collection and calls the provided callback function.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
collection |
dw.util.Collection | The collection to iterate over. |
callback |
function | The callback function to be called for each item. Takes two arguments: the current item and its index. |
Returns:
- Type
- void
(inner) map(collection, callback) → {array}
- Description:
- Creates a new array by applying the provided callback function to each item in the collection.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
collection |
dw.util.Collection | The collection to map over. |
callback |
function | The callback function to be called for each item. Takes two arguments: the current item and its index. Returns the mapped value. |
Returns:
A new array containing the mapped values.
- Type
- array
(inner) reduce(collection, callback, initialValue) → {*}
- Description:
- Applies an accumulator function against each item in the collection to reduce it to a single value.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
collection |
dw.util.Collection | The collection to reduce. |
callback |
function | The callback function to be called for each item. Takes three arguments: the accumulator, the current item, and its index. Returns the updated accumulator value. |
initialValue |
* | The initial value of the accumulator. |
Returns:
The reduced value.
- Type
- *