Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

74
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!