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

214
Views
Creating combinations of 3 arrays using for of loops

I'm trying to list all combinations of strings from 3 arrays, and assign all of those combinations to separate variables. I'm able to do it with only two arrays, but not with three for a reason I don't know. This is the code:

var i = 0;
for (var wall of [
    "red walls",
    "blue walls",
    "green walls",
    "pink walls",
    "purple walls",
    "gray walls",
    "white walls"]) {
    for (var floor of [
        "carpet floor",
        "oak-wood floor",
        "spruce-wood floor",
        "acacia-wood floor",
        "birch-wood floor"]) {
        for (var accessory of [
            "no accessory",
            "open window",
            "closed window"])
            var room = [];
            room[i] = {
                wall: wall,
                floor: floor,
                accessory: accessory
            };
            console.log("Room " + i + " - " + room[i].wall + ", " + room[i].floor + ", " + 
room[i].accessory);
            ++i;
    }    
}

Every time I run the code, it works perfectly, except for the last part of the code: the 3rd array. The accessory property always shows up as the last string of the accessory variable (closed window). I have no idea what to do, or what could fix this problem.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I rewrited a little bit your code. I think it will work right now

var walls = [
    "red walls",
    "blue walls",
    "green walls",
    "pink walls",
    "purple walls",
    "gray walls",
    "white walls"
];

var floors = [
    "carpet floor",
    "oak-wood floor",
    "spruce-wood floor",
    "acacia-wood floor",
    "birch-wood floor"
]
var accessories = [
    "no accessory",
    "open window",
    "closed window"
]

var i = 0;
for (var wall of walls) {
    for (var floor of floors) {
        for (var accessory of accessories) {
            console.log("Room " + i + " - " + wall + ", " + floor + ", " + accessory);
            ++i;
        }
    }
}
about 4 years ago · Juan Pablo Isaza Report
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!