I'm learning JavaScript and practicing merging arrays. Here's one of the methods I wrote using two for loops:
const arr1 = [4, 5, 7, 9, 8];
const arr2 = [-1, -2, 0, 12];
const arr3 = [];
for (let i = 0; i < arr1.length; i++) {
arr3.push(arr1[i]);
}
for (let i = 0; i < arr2.length; i++) {
arr3.push(arr2[i]);
}
console.log(arr3); // [4, 5, 7, 9, 8, -1, -2, 0, 12]
My questions:
Are there any performance or readability trade-offs between the manual for loop approach and using concat() or spread?
Especially in large-scale applications or performance-sensitive cases — is there a real difference?
Would love to learn the best practice here.