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

75
Vistas
Javascript Iterate elements of a first array at the position of another second array

hello i have the following code

let names = ["josh","tony","daniel"];  
let arrayplaces = ["30", "60", "90"];

names.forEach((elem, indexed) => {
  const num2 = arrayplaces[indexed];
  console.log('The user ' + elem + ' iterated in place ' + num2);
});

What I'm looking for is to iterate through all the elements of the first array into the first element of the second array, ending with the first one and continuing until it goes through the entire second array.

Example of the expected output:

The user josh iterated in place 30
The user tony iterated in place 30
The user daniel iterated in place 30

The user josh iterated in place 60
The user tony iterated in place 60
The user daniel iterated in place 60

The user josh iterated in place 90
The user tony iterated in place 90
The user daniel iterated in place 90

Does anyone know how I can do this?

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

0

You can do this by nesting loop both the array.

let names = ["josh","tony","daniel"];  
let arrayplaces = ["30", "60", "90"];

arrayplaces.forEach((element)=>{
  names.forEach((elem) => {
  console.log('The user ' + elem + ' iterated in place ' + element);
  });
 console.log('');
});

about 4 years ago · Juan Pablo Isaza Denunciar

0

You need to loop over both arrays.

for (let place of arrayplaces) {
    for (let name of names) {
        console.log(`The user ${name} iterated in place ${place}`)
    }
    console.log('\n')
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

You just should eterate every value of arrayplaces with every name. You should use 2 cycles to do that.

const names = ['josh', 'tony', 'daniel'];
const arrayplaces = ['30', '60', '90'];

names.forEach((elem, indexed) => {
  names.forEach((elem2) => {
    const num2 = arrayplaces[indexed];
    console.log(`The user ${elem2} iterated in place ${num2}`);
  });
});

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