0

I have 4-5 arrays, and I need to combine them in every possible order.

for example:

var Arr1: [R01,R02,R03,R04,R05]
var Arr2 : [A1,B2,C3,D4,E5]
var Arr3 : [ab,ac,ad,ae,af,ag,ah,ai,aj,ak]
var Arr4: [xyz,abc]

I need the positions to stay the same, so Arr1 is always in position 1, and Arr2 is always in Position 2.

I'd the like the output to look like this, cloning and updating a div each time:

R01,B2,ac,xyz
R03,D4,ag,xyz

at the moment, I'm using this, but It doesn't seem to work

var iteration = 0;
for (let a of Arr1) {
  for (let b of Arr2) {
    for (let c of Arr3) {
      for (let d of Arr4) {
        console.log(a, b, c, d);
        iteration++;
        var div = document.getElementById('comboContainer'),
          clone = div.cloneNode(true);
        clone.id = "comboContainer" + iteration;
        Text1.textContent = a;
        Text2.textContent = b;
        Text3.textContent = c;
        Text4.textContent = d;
      }
document.body.appendChild(clone);
    }
  }
}

it only seems to clone the even numbers, and only up to 100. The divs seem to all have identical Arr4 with no variation.

edit: I have added an example: https://jsfiddle.net/sgpascoe/yr4uk8nz/5/

As you can see, every box is an odd number, and every 'Arr4' is returning 'xyz'. except box 500, which is the first number?

SGPascoe
  • 33
  • 8
  • In what way doesn't it work? – Nick Jun 15 '20 at 04:41
  • It only seems to clone on even numbers, and only up to 100. I will edit my question with this information.I also notice the copies I can see don't have much variety, they all have the same Arr4 – SGPascoe Jun 15 '20 at 04:44
  • 1
    A working example would help us to understand problem – Kiran Shinde Jun 15 '20 at 04:45
  • Whats does "Arr1 is always in position 1" mean? – djcaesar9114 Jun 15 '20 at 04:45
  • @Kenny My current document has sensitive information. I will try to emulate it in jsfiddle. – SGPascoe Jun 15 '20 at 04:46
  • @djcaesar9114 I do not want the string from Arr1 to appear anywhere but the first position, so it must be R01,B2,ac,xyz or R03,D4,ag,xyz but never B2,R01,ac,xyz or D4,xyz,ag,R03 – SGPascoe Jun 15 '20 at 04:48
  • @Kenny I have updated the question with a new jsfiddle example: https://jsfiddle.net/sgpascoe/yr4uk8nz/5/ – SGPascoe Jun 15 '20 at 05:12
  • The even numbers thing is caused by the document.body.appendChild(clone); appearing one bracket lower than it should be. It will only appendChild when d==='abc' and will dummy run when d==='xyz'. – Stephen Duffy Jun 15 '20 at 05:25
  • 1
    @StephenDuffy Thanks so much! I can't believe I missed it! it's not completely perfect, but it's much better now! https://jsfiddle.net/sgpascoe/yr4uk8nz/21/ It does still seem to be hitting a limiter, which is disappointing. – SGPascoe Jun 15 '20 at 05:38

0 Answers0