Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

143
Views
How to get all possible combinations of an array but with certain elements only changing (in Javascript)

Hi can anyone please help me. I want to be able to generate all possible combinations of the array but only certain elements will be changing given two possible numbers to choose from. Their position is important too.

For example: let arr = [1,2,3, (4 or 5), (6 or 7), (8 or 9)]

I want to generate
1,2,3,4,6,8
1,2,3,4,6,9
1,2,3,4,7,8
.
.
.
.
This goes on until 1,2,3,5,7,9

I know it is very similar to binary numbers, I just don't know how to go about it and also the array may change in size so it can lead to a lot of options and possible outcomes.

Please. Someone help.

Edit: clarified the combinations I want to generate

about 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!