ArrayZip
Returns a zipped array.
arrayZip( [ 1, 2 ], [ "a", "b" ] );
// [ [ 1, "a" ], [ 2, "b" ] ]
arrayZip( [ 1, 2 ], [ 10, 20 ], ( a, b ) => a + b );
// [ 11, 22 ]
Method Signature
ArrayZip(array1=[array], array2=[array], callback=[function], parallel=[boolean], maxThreads=[any], virtual=[boolean])Arguments
array1
array
true
The first array to zip
array2
array
true
The second array to zip
callback
function
false
An optional callback function to receive the item and the current index from both zipped arrays and return a new value.
parallel
boolean
false
If true, the function will be invoked in parallel using multiple threads. Defaults to false.
false
maxThreads
any
false
The maximum number of threads to use when parallel is true. If not provided the common thread pool will be used. If a boolean value is passed, it will be assigned as the virtual argument.
virtual
boolean
false
If true, the function will be invoked using virtual thread. Defaults to false. Ignored if parallel is false.
false
Examples
Combine two arrays element-by-element
Each result element is an array of the paired values.
Result: [Alice, 30]
Zipped array length matches shortest input
Result: 2
Using the global function form
Result: [[1, x], [2, y]]
Related
Last updated
Was this helpful?
