I have 3 arrays ["s","m"]
, ["Red","Black"]
, ["1", "2"]
. I want to arrange them like this:
JavaScript
x
10
10
1
["s","Red","1"],
2
["s","Red","2"],
3
["s","Black","1"],
4
["s","Black","2"],
5
6
["m","Red","1"],
7
["m","Red","2"],
8
["m","Black","1"],
9
["m","Black","2"],
10
I’m out of idea, please help me.
Advertisement
Answer
Loop each one then just combine them into an array.
Script:
JavaScript
1
14
14
1
function test() {
2
arr1 = ["s","m"]
3
arr2 = ["Red","Black"]
4
arr3 = ["1", "2"]
5
6
arr1.forEach(x => {
7
arr2.forEach(y => {
8
arr3.forEach(z => {
9
console.log([x, y, z]);
10
});
11
});
12
});
13
}
14