Saturday, October 18, 2025
HomeLanguagesJavascriptCollect.js | crossJoin() Method

Collect.js | crossJoin() Method

Collect.js is a fluent and convenient wrapper for working with arrays and objects. The JavaScript array is first transformed into a collection and then the function is applied to the collection.

The crossJoin() method cross joins the collection with an array or collection and return all possible permutations between them.

Installation:

  • Collect.js can be installed via NPM:
    npm install --save collect.js
  • You can also use CDN of collect.js
    <script src="https://cdnjs.com/libraries/collect.js"></script>

Syntax:

collect(array1).crossJoin(array2)

Parameters: The collect() takes one argument that is converted into the collection and then crossJoin() function also take an array.

Return Value: Returns an array with all possible permutation of between them.

Below example illustrate the crossJoin() method in JavaScript:
Example: Here collect = require(‘collect.js’) is used to import the collect.js library into the file.




const collect = require('collect.js');
  
let numbers = [1, 2, 3, 4]
  
let alphabets = ['a', 'b', 'c', 'd']
  
// covert into collection
const collection = collect(numbers);
  
const permutations = collection.crossJoin(alphabets)
  
// returning the permutations
let arr =  permutations.all();
  
console.log("Permutations: ", arr);


Output

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS