Difficulty Merging two arrays

Hi there, take a look at the code below

let arr1 = ['a', 'b', 'c', 'd']

let arr2 = ['e', 'f', 'g', 'h']

Is there a way I could merge the corresponding indexes of the two arrays together? Something like this:

let res = ['a b', 'b f', 'c g', 'd h']

Of course this can be done. What have you tried so far? If you haven’t tried coding it yet then just explain to us what you think you might need to do.

let arr1 = ['a', 'b', 'c', 'd']

let arr2 = ['e', 'f', 'g', 'h']

let res = [];

for(var i=0; i<arr1.length; i++){
    res[i] = arr1[i] + " " + arr2[i];

@Wanuja97, thanks it worked

@bbsmooth , as someone that’s still trying to get comfortable with JavaScript, It was quite hard to come up with a working solution.

Agreed, if you have very little experience with JS then coding this may be hard, that’s why I suggested you just explain what you would need to do to merge these two as you wanted as a first step.

These forums aren’t really intended for people to just ask us to code their solutions for them. You will occasionally get people who are willing to do that (as in this case) but in general most people want to help you figure out how to solve your problem so that you learn while doing. That’s why we usually ask to see what you have coded so far as we expect that you have tried something and just need help getting it to work.


This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.