Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including lodash.product with all npm packages installed. Try it out:

require("lodash/package.json"); // lodash is a peer dependency. var lodashProduct = require("lodash.product")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

lodash.product v18.9.19

Calculates the Cartesian product between multiple collections.

lodash.product

_.product(...collections)

Calculates the Cartesian product between multiple collections.

argumentdescription
collectionsCollections to calculate the Cartesian product from.

Returns a new array.

dependencies

setup

npm

npm install lodash.product

ES module

import 'lodash.product';
import _ from 'lodash';

Node

require('lodash.product');
let _ = require('lodash');

browser

<script src="https://unpkg.com/lodash"></script>
<script src="https://unpkg.com/lodash.product"></script>

usage

let product = _.product([false, true], ['a', 'b', 'c'], [{}]);
// => [[false, 'a', {}], [false, 'b', {}], [false, 'c', {}], [true, 'a', {}], [true, 'b', {}], [true, 'c', {}]]

let array = [1, 2, 3];
let product = _.product(array, array);
// => [[1, 1], [1, 2], [1, 3], [2, 1], [2, 2], [2, 3], [3, 1], [3, 2], [3, 3]]

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free