18.10.0 • Published 1 year ago

lodash.product v18.10.0

Weekly downloads
2,402
License
MIT
Repository
github
Last release
1 year ago

lodash.product

_.product(...collections)

Calculates the Cartesian product between multiple collections.

argumentdescription
collectionsCollections to calculate the Cartesian product from.

Returns a new array.

setup

npm

npm i 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]]