You can push multiple elements into an array in the following way

var a = [];
    
a.push(1, 2, 3);

console.log(a);
Run code snippetEdit code snippet Hide Results Copy to answer Expand

Answer from amit1310 on Stack Overflow
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ JavaScript โ€บ Reference โ€บ Global_Objects โ€บ Array โ€บ push
Array.prototype.push() - JavaScript | MDN
July 12, 2026 - The push() method of Array instances adds the specified elements to the end of an array and returns the new length of the array.
Discussions

Push multiple elements to array
This would create and return a new array instead of pushing items to the same array. More on stackoverflow.com
๐ŸŒ stackoverflow.com
Is there a reason JavaScript developers don't use Array.push()? - Stack Overflow
I realise I'm only a hobbyist, but I do use push(), and now I feel like I'm missing some hitherto secret contraindication for such usage... ... I frequently use it, although I prefer an indexer where it makes more logical sense (like a for loop). Tim M. โ€“ Tim M. 2013-03-27 00:28:15 +00:00 Commented Mar 27, 2013 at 0:28 ยท People do sometimes think it's faster. See Why is array... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Copy array items into another array
I have a JavaScript array dataArray which I want to push into a new array newArray. Except I don't want newArray[0] to be dataArray. I want to push in all the items into the new array: var newArra... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Which is faster in PHP, $array[] = $value or array_push($array, $value)? - Stack Overflow
What's better to use in PHP for appending an array member, $array[] = $value; or array_push($array, $value); ? Though the manual says you're better off to avoid a function call, I've also read $... More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
daily.dev
daily.dev โ€บ home โ€บ blog โ€บ webdev โ€บ javascript push() and pop(): array methods guide
JavaScript push() and pop(): Array Methods Guide | daily.dev
May 25, 2026 - These tools change the original array when you use them. The push() method in JavaScript lets you add one or more items to the end of a list (array) and tells you how long the list is after adding them.
๐ŸŒ
PHP
php.net โ€บ manual โ€บ en โ€บ function.array-push.php
PHP: array_push - Manual
If you're adding multiple values to an array in a loop, it's faster to use array_push than repeated [] = statements that I see all the time: <?php class timer { private $start; private $end; public function timer() { $this->start = microtime(true); } public function Finish() { $this->end = microtime(true); } private function GetStart() { if (isset($this->start)) return $this->start; else return false; } private function GetEnd() { if (isset($this->end)) return $this->end; else return false; } public function GetDiff() { return $this->GetEnd() - $this->GetStart(); } public function Reset() { $t
๐ŸŒ
Medium
medium.com โ€บ an-idea โ€บ javascript-arrays-push-pop-shift-unshift-adc8fb815fc0
Medium
October 10, 2021 - JavaScript Arrays: push(), pop(), shift() & unshift() When working with arrays, it is important to understand the different types of methods and how they transform your data. push(), pop(), shift() โ€ฆ
Find elsewhere
๐ŸŒ
Coddy.Tech
coddy.tech โ€บ learn โ€บ courses โ€บ array methods in javascript โ€บ push & pop
Push & Pop โ€“ Array Methods in JavaScript | Coddy
The push() method is used to add one or more elements to the end of an array and returns the new length of the modified array. The pop() method removesโ€ฆ
๐ŸŒ
DEV Community
dev.to โ€บ technoph1le โ€บ the-javascript-arraypush-method-explained-5d4m
The JavaScript `Array.push()` method explained - DEV Community
November 24, 2022 - The Array.push() method adds one or more elements to the end of an array and returns the new length of the array.
๐ŸŒ
Codefinity
codefinity.com โ€บ courses โ€บ v2 โ€บ e007c646-1d42-4c75-b967-8c19bd28aa06 โ€บ fd2b0786-7367-4686-97ac-9f3ff4c21aba โ€บ f6c39add-24c6-479f-bd57-eddf5d0b4d5d
Learn Adding Elements with push and unshift | Getting Started with Array Basics
The push method appends one or more elements to the end of an array, making it ideal when you want to add items in the order they arrive, such as building a list of recent messages or appending new data records.
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ javascript-append-to-array-a-js-guide-to-the-push-method-2
JavaScript Append to Array: a JS Guide to the Push Method
April 19, 2021 - Sometimes you need to append one or more new values at the end of an array. In this situation the push() method is what you need. The push() method will add one or more arguments at the end of an array in JavaScript: let arr = [0, 1, 2, 3];
๐ŸŒ
W3Schools
w3schools.com โ€บ php โ€บ func_array_push.asp
PHP array_push() Function
The array_push() function inserts one or more elements to the end of an array.
๐ŸŒ
GameMaker
manual.gamemaker.io โ€บ beta โ€บ en โ€บ GameMaker_Language โ€บ GML_Reference โ€บ Variable_Functions โ€บ array_push.htm
array_push
With this function you can push a value (or values) onto the end of an array without having to know the length of the array.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ javascript โ€บ javascript-array-push-method
JavaScript Array push() Method - GeeksforGeeks
The push() method in JavaScript adds one or more elements to the end of an array and returns the new length of the array.
Published: April 15, 2025
Top answer
1 of 9
181

I personally feel like $array[] is cleaner to look at, and honestly splitting hairs over milliseconds is pretty irrelevant unless you plan on appending hundreds of thousands of strings to your array.

I ran this code:

$t = microtime(true);
$array = array();
for($i = 0; $i < 10000; $i++) {
    $array[] = $i;
}
print microtime(true) - $t;
print '<br>';
$t = microtime(true);
$array = array();
for($i = 0; $i < 10000; $i++) {
    array_push($array, $i);
}
print microtime(true) - $t;

The first method using $array[] is almost 50% faster than the second one.

Some benchmark results:

Run 1
0.0054171085357666 // array_push
0.0028800964355469 // array[]

Run 2
0.0054559707641602 // array_push
0.002892017364502 // array[]

Run 3
0.0055501461029053 // array_push
0.0028610229492188 // array[]

This shouldn't be surprising, as the PHP manual notes this:

If you use array_push() to add one element to the array it's better to use $array[] = because in that way there is no overhead of calling a function.

The way it is phrased I wouldn't be surprised if array_push is more efficient when adding multiple values. Out of curiosity, I did some further testing, and even for a large amount of additions, individual $array[] calls are faster than one big array_push. Interesting.

2 of 9
45

The main use of array_push() is that you can push multiple values onto the end of the array.

It says in the documentation:

If you use array_push() to add one element to the array it's better to use $array[] = because in that way there is no overhead of calling a function.

๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ php โ€บ how-to-use-array_pop-and-array_push-methods-in-php
How to use array_pop() and array_push() methods in PHP ? - GeeksforGeeks
July 23, 2025 - The array_push() method is used to push multiple elements in the array simultaneously. Elements are inserted in the order in which they are specified in the method call.