How do you append one or multiple items to the end of an array in JavaScript? | A1Lab@FahadM to JavaScriptEnglish •
edit-2
11 days ago

How do you append one or multiple items to the end of an array in JavaScript?

message-square
0

Use **array.push(item1, item2)** to append items in place, or the **spread syntax ([…array, newItem]`)** when you need an immutable copy (such as in React state updates).

In-Place Append vs. Immutable Append

const tags = ["js", "web"];

// 1. Mutate in place with .push() (fastest)
tags.push("frontend", "es6");
console.log(tags); // ["js", "web", "frontend", "es6"]

// 2. Non-mutating append with spread operator (best for React/Redux)
const nextTags = [...tags, "node", "api"];

Merging Another Array at the End

const moreTags = ["css", "html"];
tags.push(...moreTags); '