Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

182
Vistas
How do arrange arrays with different combinations?

I have 3 arrays ["s","m"], ["Red","Black"], ["1", "2"]. I want to arrange them like this:

["s","Red","1"],
["s","Red","2"], 
["s","Black","1"], 
["s","Black","2"],

["m","Red","1"],
["m","Red","2"], 
["m","Black","1"], 
["m","Black","2"],

I'm out of idea, please help me.

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

Loop each one then just combine them into an array.

Script:

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]);
      });
    });
  });
}

Output:

output

about 4 years ago · Juan Pablo Isaza Denunciar

0

  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])
           
        }
    }
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

you can make 3 nested loops, some thing like:

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
           }
       }
   }
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda