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

96
Vistas
Javascript 2D array filled with loop

I am trying to make a 2D array javascript using looping, with a result like this:

[[a1,a2,a3,a4,a5][b1,b2....]..[...e3,e4,e5]]

I have tried multiple different things, using for loops and the below, but am unable to create as needed.

var cols = [1,2,3,4,5];
var rows = ["a", "b", "c","d", "e"];

var grid = [ for (r of rows) [ for (c of cols) r+c ] ];

any help is appreciated.

Thanks

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

0

You can get your desired result using a nested map over the rows and columns:

var cols = [1,2,3,4,5];
var rows = ["a", "b", "c","d", "e"];

var grid = rows.map(r => cols.map(c => r + c));

console.log(grid)

about 4 years ago · Juan Pablo Isaza Denunciar

0

It looks like @Nick beat me to it again ;-) but, obviously, this is the solution:

var cols = [1,2,3,4,5];
var rows = ["a", "b", "c","d", "e"];

const res = rows.map(r=>cols.map(c=>r+c));

console.log(res);

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