cartesianProduct es-toolkit
Computes the Cartesian product of the input arrays.
Usage
cartesianProduct(...arrs)
Use cartesianProduct when you want every possible combination of one element from each input array.
The function walks through the rightmost array first, picking each element in order. Once it has gone through every element of the rightmost array, it picks the next element from the array one position to its left and starts the rightmost array over from the beginning. This process repeats across every array, working from right to left.
If any input array is empty, the product is empty. With no arguments, the result is a single empty tuple.
Parameters
The arrays to take the product of.
Returns
An array of tuples representing the Cartesian product.
Try It
::: sandpack
:::
Source: es-toolkit
Re-exported verbatim from es-toolkit. Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.