JavaScript Array push() Method

Beginner
⏱️ 7 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Mutates

What You’ll Learn

The push() method adds one or more elements to the end of an array and returns the new length. This tutorial covers syntax, five examples, spread merging, stack patterns with pop(), and why you cannot chain .push() on its return value.

01

Syntax

arr.push(...)

02

Add end

Append items

03

Returns

New length

04

Multiple

Many args OK

05

Stack

LIFO + pop

06

ES3

Universal

Introduction

Need to grow a list at runtime—collect user choices, queue tasks, or build a shopping cart? push() appends values to the back of an array in one call. It is one of the most common array operations in JavaScript.

Like pop(), push() mutates the original array. If you need a new array without changing the source, use spread or concat() instead.

Understanding the push() Method

array.push(element1, element2, ...) inserts each argument at index length, then length + n, and so on. The return value is the updated length—a number, not the array.

You can pass as many arguments as you need in a single call. To merge another array’s items, spread them: arr.push(...otherArray).

💡
Beginner Tip

fruits.push("a", "b").push("c") does not work—the first push returns a number, and numbers have no push method. Call push on the array variable each time.

📝 Syntax

General form of Array.prototype.push:

JavaScript
array.push(element1, element2, /* ... , */ elementN)

Parameters

  • element1, element2, ... — one or more values to append at the end.

Return value

  • The new length of the array (number).

Side effects

  • Mutates the array: elements added at the end, length increases.

Common patterns

  • arr.push(item) — add one element.
  • arr.push(a, b, c) — add several at once.
  • arr.push(...other) — merge another array in place.
  • const n = arr.push(x) — capture new length.

⚡ Quick Reference

GoalCode
Add to endarr.push(value)
Add multiplearr.push(a, b, c)
Return valueNew length (number)
Merge arrays in placearr.push(...other)
Mutates array?Yes

📋 push() vs pop() vs unshift() vs concat()

Choose based on end vs start insertion and whether you need to mutate.

push
add last

Mutates

pop
remove last

Stack pair

unshift
add first

Slower at scale

concat
new array

Immutable

Examples Gallery

Open DevTools Console (F12) or use Try-it labs. Example N maps to ?tryit=N.

📚 Getting Started

Append values to the end of an array.

Example 1 — Add Elements to the End

Append 4 and 5 to a number array.

JavaScript
const numbers = [1, 2, 3];

numbers.push(4, 5);

console.log(numbers);
// [1, 2, 3, 4, 5]
Try It Yourself

How It Works

Both values are added in order at indices 3 and 4. The same array reference now holds five elements.

Example 2 — push() Returns the New Length

The return value is a number, not the array—so chaining .push() fails.

JavaScript
const fruits = ["apple", "orange"];

const newLength = fruits.push("banana", "grape");

console.log(newLength);
// 4

console.log(fruits);
// ["apple", "orange", "banana", "grape"]

// This would throw — push returns a number:
// fruits.push("kiwi").push("mango");
Try It Yourself

How It Works

Use the array variable for each push. Store the length only when you need to track size after insertion.

📈 Practical Patterns

Merge arrays, stacks, and immutable alternatives.

Example 3 — Merge Another Array with Spread

Append all items from vegetables into fruits.

JavaScript
const fruits = ["apple", "orange"];
const vegetables = ["carrot", "broccoli"];

fruits.push(...vegetables);

console.log(fruits);
// ["apple", "orange", "carrot", "broccoli"]
Try It Yourself

How It Works

Spread unpacks vegetables into individual arguments. Without spread, push(vegetables) would add one nested array element.

Example 4 — Build a Stack with push() and pop()

Push adds to the top; pop removes from the top (LIFO).

JavaScript
const stack = [];

stack.push("task-1");
stack.push("task-2");
stack.push("task-3");

console.log(stack.pop());
// "task-3"

console.log(stack);
// ["task-1", "task-2"]
Try It Yourself

How It Works

The last pushed item is the first popped—ideal for undo history and depth-first traversal.

Example 5 — push() Mutates; concat() Returns a New Array

When immutability matters, avoid in-place push.

JavaScript
const base = [1, 2];

const merged = base.concat(3, 4);

console.log("concat result:", merged);
// [1, 2, 3, 4]

console.log("base unchanged:", base);
// [1, 2]

base.push(3, 4);

console.log("after push:", base);
// [1, 2, 3, 4]
Try It Yourself

How It Works

concat leaves the original alone. push updates it—important in React/state patterns where you often prefer [...arr, item].

🚀 Common Use Cases

  • Dynamic lists — collect user input or API results.
  • Stack operations — pair with pop() for LIFO.
  • Batch append — multiple arguments in one call.
  • Merge in placetarget.push(...source).
  • Build queues from the end — when order allows.
  • Track size — use return value as new length.

🧠 How push() Runs

1

Read arguments

Engine collects all values passed to push.

Input
2

Write at end

Each value stored starting at current length.

Append
3

Update length

Array grows by the number of arguments.

Mutate
4

Return new length

Caller gets a number, not the array reference.

📝 Notes

  • Mutates the array—length increases.
  • Returns new length, not the array (no chaining).
  • Accepts any number of arguments in one call.
  • Use spread to flatten array arguments: push(...arr).
  • O(1) amortized for end insertion; faster than unshift at scale.
  • For immutable updates, prefer [...arr, x] or concat.
  • ES3—supported everywhere JavaScript runs.

Browser & Runtime Support

Array.prototype.push() is one of the oldest array methods, available since JavaScript 1.2 / ES3.

Baseline · ES3

Array.prototype.push()

Supported in every browser ever shipped with JavaScript arrays, including Internet Explorer 3+, and all Node.js versions.

100% Universal support
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
Array.push() Universal

Bottom line: Safe to use in any environment. No polyfill ever needed.

Conclusion

push() appends one or more elements to the end and returns the new length. Use it for dynamic growth and stack patterns with pop(); choose concat or spread when you must keep the original array unchanged.

Next, learn reduce() to fold an array into a single value.

💡 Best Practices

✅ Do

  • Pass multiple items in one push(a, b, c) call when handy
  • Use push(...arr) to merge arrays in place
  • Pair with pop for stack behavior
  • Use spread or concat when immutability is required
  • Store return value when you need the updated length

❌ Don’t

  • Chain .push() on the return value (it is a number)
  • Push an array without spread when you mean merge items
  • Forget mutation affects all references to the array
  • Use unshift when end insertion is enough
  • Assume push returns the updated array

Key Takeaways

Knowledge Unlocked

Five things to remember about Array.push()

Append to the end and get the new length back.

5
Core concepts
🔢 02

Returns

New length.

Number
03

Mutates

In place.

Side effect
🗃 04

Stack

With pop.

Pattern
05

Spread

Merge arrays.

Trick

❓ Frequently Asked Questions

push() adds one or more elements to the end of an array, increases length, and returns the new length.
Yes. push() changes the array in place by appending elements at the end.
The new length of the array (a number), not the array itself. You cannot chain .push() on the return value.
push() adds to the end; pop() removes from the end. Together they implement a LIFO stack.
push() adds at the end (fast). unshift() adds at the start (slower on large arrays because other elements shift).
push() has been available since JavaScript 1.2 / ES3. It works in every browser including very old environments.
Did you know?

Modern code often writes [...arr, newItem] instead of arr.push(newItem) when updating React or Redux state, because spread creates a new array reference without mutating the old one.

Continue to reduce()

Learn how to combine all array elements into one accumulated result.

reduce() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful