Tengo 3 matrices ["s","m"] , ["Red","Black"] , ["1", "2"] . Quiero ordenarlos así:
["s","Red","1"], ["s","Red","2"], ["s","Black","1"], ["s","Black","2"], ["m","Red","1"], ["m","Red","2"], ["m","Black","1"], ["m","Black","2"],se me ha ido la idea por favor ayúdenme.
Haga un bucle en cada uno y luego combínelos en una matriz.
function test() { arr1 = ["s","m"] arr2 = ["Red","Black"] arr3 = ["1", "2"] arr1.forEach(x => { arr2.forEach(y => { arr3.forEach(z => { console.log([x, y, z]); }); }); }); } let a = ["s","m"] let b = ["Red","Black"] let c = ["1", "2"] for(let i = 0 ; i < a.length ; i++){ for(let j = 0 ; j < b.length ; j++){ for(let k = 0 ; k < c.length ; k++){ console.log(a[i], b[j], c[k]) } } }puedes hacer 3 bucles anidados, algo como:
for (int i = 0; i<2; i++) { for(int j = 0; j<2; j++) { for(int k = 0; k<2; k++) { //put your code here } } }