
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
How to get all combinations of some arrays in JavaScript?
You can use your own function to get all combinations.
Example
Following is the code −
function combination(values) { function * combinationRepeat(size, v) { if (size) for (var chr of values) yield * combinationRepeat(size - 1, v + chr); else yield v; } return [...combinationRepeat(values.length, "")]; } var output = combination([4,5]); console.log(output);
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo306.js.
Output
This will produce the following output −
PS C:\Users\Amit\javascript-code> node demo306.js [ '44', '45', '54', '55' ]
- Related Articles
- Find all substrings combinations within arrays in JavaScript
- Algorithm to get the combinations of all items in array JavaScript
- All combinations of sums for array in JavaScript
- Generate all combinations of supplied words in JavaScript
- Generating combinations from n arrays with m elements in JavaScript
- Python program to get all pairwise combinations from a list
- How to get all the combinations of the keypad value in a mobile by backtracking using C#?
- Finding all possible combinations from an array in JavaScript
- How to get the difference between two arrays in JavaScript?
- How to get single array from multiple arrays in JavaScript
- JavaScript function that generates all possible combinations of a string
- How to dynamically combine all provided arrays using JavaScript?
- Print all combinations of factors in C++
- How to find all combinations of a vector elements without space in R?
- How to generate a list of all possible 4 digits combinations in Excel?

Advertisements