Contact Free trial Login

countBy

countBy(Array<T>, (T) -> Boolean): Number

Counts the elements in an array that match the results of a function.

Parameters

Name Description

array

The input array that contains elements to match.

matchingFunction

A function to apply to elements in the input array.

Example

This counts the values in the array that are equal to the result of the matchingFunction ((($ mod 2) == 0)).

Source

 %dw 2.0
 import * from dw::core::Arrays
 output application/json
 ---
{ "countBy" : [1, 2, 3, 4] countBy (($ mod 2) == 0) }

Output

{ "countBy": 2 }

We use cookies to make interactions with our websites and services easy and meaningful, to better understand how they are used and to tailor advertising. You can read more and make your cookie choices here. By continuing to use this site you are giving us your consent to do this.