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

132
Views
Create an array from others

I'm trying to make an array from a few arrays.

For example :

array1= ['Joe','James','Carl','Angel','Jimmy',];
array2= ['22','11','29','43','56',];
array3= ['red','blue','orange','brown','yellow',];

I need to create a new array pushing by index. What I'm trying to do is something like this :

newArray=['Joe22red','james11blue','Carl29orange','Angel43brown','Jimmy56yellow']

How can I do that ?

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

array1= ['Joe','James','Carl','Angel','Jimmy'];
array2= ['22','11','29','43','56'];
array3= ['red','blue','orange','brown','yellow'];
newArray = []
for (let i =0; i<Math.max(array1.length, array2.length, array3.length); i++) {
    newArray.push(`${array1[i]}${array2[i]}${array3[i]}`)
}
console.log(newArray);

about 4 years ago · Juan Pablo Isaza Report

0

You can use map function to find out the result

const array1= ['Joe','James','Carl','Angel','Jimmy',];
const array2= ['22','11','29','43','56',];
const array3= ['red','blue','orange','brown','yellow',];

const result = array1.map(
  (item, index) => `${item}${array2[index]}${array3[index]}`
)
console.log(result);

about 4 years ago · Juan Pablo Isaza Report

0

And if we don´t know how many arrays are? Here is solution

const array1= ['Joe','James','Carl','Angel','Jimmy',];
const array2= ['22','11','29','43','56',];
const array3= ['red','blue','orange','brown','yellow',];

const data = [array1, array2, array3];

const result = data[0].map((_, index) => data.map((arr) => arr[index]).join(''));

console.log(result);
.as-console-wrapper{min-height: 100%!important; top: 0}

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!