Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8240307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:26:49+00:00 2026-06-07T20:26:49+00:00

long time reader, first time writer here. I’m trying to figure out all possible

  • 0

long time reader, first time writer here.

I’m trying to figure out all possible combinations of an undetermined set of javascript arrays, but can’t seem to find much help.

So, if you can imagine groups of dropdowns (this is the eventual use) where there could be any number of dropdowns the user defines, and each dropdown has any number of possible values that the user also defines. (Only one value in each option can be chosen at one time.)

So as an example…

var options = [
{
    label:"Colors", 
    values:["red", "green", "blue", "etc"]
},
{
    label:"Sizes",
    values:["small", "medium", "large", "xl", "etc"]
},
{
    label:"styles",
    values:["t-shirt", "v-neck", "hoodie", "vest", "etc"]
}
//and any number of options, with any numbers of values
];

Now from there I need to generate all possible outcomes, with one value selected from each option (bonus love if the solution can have an option optional or not though, so maybe sometimes it could be set to generate all possible combinations including if only one value is selected).

So I’m hoping for a solution like

function combinations(options, option_optional){

}

with only unique combinations, then I can build a list like these

if an option is optional:

[
    ["red"],
    ["red", "large"],
    ["red", "large", "tshirt"],
    ["large"],
    ["large", "t-shirt"]

etc…

or if all options must be selected:

[
    ["red", "large", "t-shirt"],
    ["red", "medium", "t-shirt"],

etc.

I tried looking at other solutions out there but could only find ones that gave back ALL possible combinations.

Any help is appreciated and if you prefer using jquery’s $.each for loops, that’s fine too. Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T20:26:51+00:00Added an answer on June 7, 2026 at 8:26 pm

    After returning to this problem after a couple months again, I found the answer to my problems here:
    https://stackoverflow.com/questions/4796678/javascript-golf-cartesian-product?lq=1

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

long time reader/first time poster here. So I've got a checkbox array that posted
'Long time reader, first time poster' here. I'm in the process of making a
Long time reader first time typer. I've been trying to setup a simple spring3
Long time reader/ first time poster here, with a question I suspect will be
Long time reader, first time poster here. I'm creating a test app that creates
Long time reader, first time poster. It's time to mine this site for all
long time reader first time user. I'm putting together my first RoR application and
Long time reader, first time poster. Any help is greatly appreciated. I have crafted
(Long time reader of SO, first time asking a q. I'm quite new to
first time poster, long time reader so be gentle with me :) See the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.