Example 1 — Merge Two Arrays
Combine fruits1 and fruits2 into a new list.
const fruits1 = ["apple", "orange"];
const fruits2 = ["banana", "grape"];
const merged = fruits1.concat(fruits2);
console.log(merged);
// ["apple", "orange", "banana", "grape"]
console.log(fruits1);
// ["apple", "orange"] — unchanged How It Works
- Start with two lists.
fruits1is the caller;fruits2is the argument. - Build a new array.
concatcopiesfruits1, then appends every item fromfruits2. - Use the return value. Store it in
merged— that is the combined list. - Sources stay safe.
fruits1andfruits2are not modified.

