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

124
Views
Mezclar valor de matriz javascript

Tengo una matriz que tiene una matriz anidada como esta

 const arr = [[red,green],[house,roof,wall]]

¿Hay alguna forma de mezclar la matriz anidada para que la salida sea así?

 red house, red roof, red wall, green house, green roof, green wall
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Por favor verifique el código a continuación

 const arr = [['red','green'],['house','roof','wall']]; const array1 = arr[0]; const array2 = arr[1]; const new_arr = []; for(let i=0; i< array1.length; i++){ for(let j=0; j< array2.length; j++){ new_arr.push(array1[i] + ' ' +array2[j]); } } console.log(new_arr); // output ['red house', 'red roof', 'red wall', 'green house', 'green roof', 'green wall'] console.log(new_arr.join(',')); // output: red house, red roof, red wall, green house, green roof, green wall

about 4 years ago · Juan Pablo Isaza Report

0

Un map() con 2 join() para convertirlo en una cadena

 const arr = [ [ 'red', 'green' ],['house','roof','wall']]; const res = arr[0].map(a => arr[1].map(b => `${a} ${b}`).join(', ')).join(', '); console.log(res);

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!