0

This is a little difficult for me to describe in a single sentence/title. So, please forgive me if the title makes no sense at all.

To try and make it simpler and hopefully more clear, I'm going to number the arrays.

I wish to use array 1 to create multiple array 2s. I wish to put in the array 2s different values and lengths.

Then I wish to loop through array 2s to loop the values of said arrays

@Kinglish

What I currently have is the following:

let arrayOneCount = 3;
let arrayOne = [];
let arrayTwoCount = 1;
while (arrayTwoCount < arrayOneCount) {
    arrayOne.push("arrayTwo" + (arrayTwoCount - 1));
    arrayTwoCount++;
}

arrayTwo0 = [
    "1",
    "2",
    "3"
];

arrayTwo1 = [
    "1",
    "2"
];

arrayTwo2 [
    "1",
    "2",
    "3",
    "4"
];

What I want to do with this is to loop through these arrays with a loop within that loop to loop the values of each respective array.

I have tried to do

arrayOne[0] = [
        "1",
        "2",
        "3"
];

But that didn't work out.

Don't make "arrayTwo0" etc., make an array of arrays: let arrayTwo = [[1, 2, 3], [...], ...]. Then your syntax already works. – deceze

That fixed it. Thanks :)

Donder172
  • 1
  • 1
  • 1
    do you have an example of the result? and input? – Nina Scholz Sep 02 '22 at 18:06
  • What have you already tried and where exactly are you stuck? – PM 77-1 Sep 02 '22 at 18:07
  • I'm pretty new to this site in the sense of posting on it, so I accidentally reposted @nina's comment, but deleted it, I think. I don't have any functioning examples. I've tried to literally create the arrays in a loop to later add their values, which didn't work. Instead of looping the values I wanted to, it looped almost every single letter. I have tried to use a variable to try to loop through the arrays, but that didn't work at all. I'm stuck at adding the values to the second arrays, but I have the feeling that I haven't even created the arrays correctly within the first array. – Donder172 Sep 02 '22 at 18:15
  • Where is the data coming from? Without sample (even broken) code and sample data it's hard to visualize and recommend an exact solution. – James Sep 02 '22 at 18:17
  • Just add an example of array#1, an example of what you want array#2 to look like, and a stab at what you think the process will be. Add those to your question and people will help if they can – Kinglish Sep 02 '22 at 18:19
  • Don't make "`arrayTwo0`" etc., make an *array of arrays*: `let arrayTwo = [[1, 2, 3], [...], ...]`. Then your syntax already works. – deceze Sep 02 '22 at 18:56
  • I'm still confused as to what the desired output is. is it A: arra1[array2[array2two[...]]], or is it B: array1[...] array2[...] array2two[...] – FujiRoyale Sep 02 '22 at 19:24
  • 1
    deceze got me the solution. @FujiRoyale – Donder172 Sep 02 '22 at 20:06

0 Answers0