Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

76
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda