githubEdit

ArrayGroupBy

Returns a struct of keys returned from the predicate function and values of arrays of matching rows.

 values = [ 1, 2, 3, 4 ];
 values.groupBy( ( value ) => value % 2 ? "odd" : "even" );
 // { odd: [ 1, 3 ], even: [ 2, 4 ] }
 

Method Signature

ArrayGroupBy(array=[array], callback=[function])

Arguments

Argument
Type
Required
Description
Default

array

array

true

The array to group.

callback

function

true

The function to invoke for each item. The function will be passed 3 arguments: the value, the index, the array. You can alternatively pass a Java Predicate which will only receive the 1st arg.

Examples

Last updated

Was this helpful?