How would you implement the Cartesian product of multiple arrays in JavaScript? As an example, should return Answer Here is a functional solution to the problem (without any mutable variable!) using reduce and flatten, provided by underscore.js: Remark: This solution was inspired by http://cwestblog.com/2011/05/02/cartesian-product-of-multiple-arrays/