Task of Challenge #24
Create a function that will merge two arrays and return the result as a new array. The two arrays: [9, 8, 7, 6], [1, 2, 3, 4] .
Solution
Explanation
The function mergeArrays
has two inputs (array1
and array2
). It also does create an empty array tempArray
where the combined and merged array will be stored to.
This time you need two for loops to cover the merging process. You simply push all elements of the first array to the variable tempArray
. When this is done, you approach the second array and push also each element into tempArray
.
Once you’ve iterated over both arrays and all elements are stored into tempArray
you just do the return and already have it. A merged array.
This isn’t the best method you should use. It is a good way to practice loops, but in terms of functionality, clean code, and extensibility you should take my JavaScript Course, where I introduce you also to all kinds of array methods to write maintainable and scalable code – a must-have for every JavaScript Developer.
To get a discount, just subscribe to my newsletter.
The output for the code above is:

Become a Bullet Proof Developer and Seek My Coding Adventures

Sharpen Your JavaScript Coding Skills by Creating GOOD Code
Upgrade Your Legacy Coding Style With These 6 Modern Ways of Coding

And How These 3 Famous TV Shows Make You Write Excellent JavaScript Code
This Domain Is Good!
I have to thank you for the efforts you have put in penning this website. Im hoping to see the same high-grade content by you in the future as well. In truth, your creative writing abilities has motivated me to get my own website now 😉