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

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

console.log(a);

Answer from amit1310 on Stack Overflow
🌐
Bacancy Technology
bacancytechnology.com › qanda › javascript › push-multiple-elements-to-array-in-javascript
How to Push Multiple Elements to Array in JavaScript
let a = []; Array.prototype.push.apply(a, [1, 2]); console.log(a); // [1, 2] Alternatively, you can use the spread operator, which is often simpler and more modern: let a = []; a.push(...[1, 2]); console.log(a); // [1, 2] Work with our skilled ...
🌐
Quora
quora.com › How-do-you-push-multiple-objects-into-an-array
How to push multiple objects into an array - Quora
1. Push() 2. Unshift() 3. Spread operator 1. Push(): This operator add multiple items in end of an array. # Lets take an empty array [code]let array = []; [/code]#add elements using push operator [code...
🌐
Vultr Docs
docs.vultr.com › javascript › standard-library › Array › push
JavaScript Array push() - Add Elements to Array | Vultr Docs
September 27, 2024 - Start with an established array. Use the push() method to simultaneously add multiple elements.
🌐
Stack Abuse
stackabuse.com › bytes › push-an-object-to-an-array-in-javascript
Push an Object to an Array in JavaScript
July 23, 2022 - To achieve this, we'll use the ... and it will add it to the end of the array. To add multiple objects to an array, you can pass multiple objects as arguments to the push() method, which will add all of the items to the end of the array....
🌐
Quora
quora.com › How-do-I-add-multiple-objects-to-a-single-array-list-in-Javascript
How to add multiple objects to a single array list in Javascript - Quora
Answer (1 of 4): To add multiple objects to a single array , there are two functions you can use : 1. push() : Using this function you can append as many values you want to the array giving one at a time . for eg: var arr=[] [code ]arr.push ...
Find elsewhere
🌐
W3Schools
w3schools.com › jsref › jsref_push.asp
JavaScript Array push() Method
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST ... Array[ ] Array( ) at() concat() constructor copyWithin() entries() every() fill() filter() find() findIndex() findLast() findLastIndex() flat() flatMap() forEach() from() includes() indexOf() isArray() join() keys() lastIndexOf() length map() of() pop() prototype push() reduce() reduceRight() rest (...) reverse() shift() slice() some() sort() splice() spread (...) toReversed() toSorted() toSpliced() toString() unshift() values() valueOf() with() JS Boolean
🌐
RSWP Themes
rswpthemes.com › home › javascript tutorial › how to push multiple objects in array in javascript
How To Push Multiple Objects In Array In Javascript
March 26, 2024 - In this article, we will explore the step-by-step process of pushing multiple objects into an array in JavaScript.
🌐
HubSpot
blog.hubspot.com › home › the hubspot website blog
Everything You Need to Know About the JavaScript Array ...
HubSpot’s Website Blog covers everything you need to know to build maintain your company’s website.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-array-push-method
JavaScript Array push() Method - GeeksforGeeks
The array push() function adds one or more values to the end of the array and returns the new length. This method changes the length of the array. An array can be inserted into the object with push() function.
Published   April 15, 2025
🌐
Shiksha
shiksha.com › home › it & software › it & software articles › programming articles › javascript array push
JavaScript Array Push - Shiksha Online
December 18, 2023 - The JavaScript array.push() method adds one or more elements to the end of an array, directly modifying the original array.
🌐
GitHub
github.com › bobbyhadz › javascript-push-multiple-values-to-array
GitHub - bobbyhadz/javascript-push-multiple-values-to-array: A repository for an article at https://bobbyhadz.com/blog/javascript-push-multiple-values-to-array
A repository for an article at https://bobbyhadz.com/blog/javascript-push-multiple-values-to-array - bobbyhadz/javascript-push-multiple-values-to-array
Author   bobbyhadz
🌐
EDUCBA
educba.com › home › software development › software development tutorials › javascript tutorial › javascript array push
JavaScript Array Push | Adding Elements in Array with Different Examples
June 9, 2023 - In this way, we can use multiple ... value is directly assigned using an index. We can use the push() method to add the elements at the end of an array, increasing its length. This is a guide to JavaScript Array Push...
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
Reddit
reddit.com › r/learnjavascript › using push a few times or just once
r/learnjavascript on Reddit: Using push a few times or just once
April 12, 2023 -

Hey, so maybe this is a silly question but I was wondering how to measure the performance of push method, would it be preferable to push a few elements into an array at once or just push it a couple of times? I'm using console.time method to measure the diff between these two approaches, maybe there is a better/more reliable way to test this?

Example:

// one call to push method

arr.push({a:'a', b: 'b'}, {c:'c', d: 'd'});

// n calls to push method

arr.push({a:'a', b: 'b'});

arr.push({c:'c', d: 'd'});

It's just to see which one is faster more than the obvious thing to do (just push it all in one call)

🌐
Medium
habtesoft.medium.com › add-elements-to-an-array-in-javascript-a9cc6cd9469f
Add elements to an array in JavaScript | by habtesoft | Medium
October 18, 2024 - In this example, we have an array of numbers and we use the push() method to add a single element and multiple elements to the end of the array. ... The splice() method can also be used to add elements to an array in JavaScript.
Top answer
1 of 1
1
Objects behave a bit differently from most other datatypes in JavaScript. When you assign an object to a variable or add it to an array or anything like that. JavaScript does not make a copy of the object, it makes the new variable (or array item) contain the exact same object you assigned. To illustrate this take a look at this code: ```JavaScript var example = { message: "Hello" }; var example2 = example; example.message = "world"; console.log(example2); ``` We create an object example then we create a new variable example2 and assign example to it. Then we change the message property of example and then we print out example2. Now what do you think will be printed out? If Objects worked like Strings and Numbers then you would expect { message: 'Hello' } to be printed out. Since that is what example contained when it was assigned to example2. But in reality the above code prints out { message: 'world' }. This is because these two variables don't hold independent copies of the object, they hold the exact same object. Which means that even though there are two variables at play there is actually only one object created in the above code. You just have two variables pointing at it. With that knowledge if you take a look at your code the behavior you experience should make a bit more sense. You create one object at the start of your code, then you assign it the details of one student. Then you add a pointer to that object to the array. Then you change that same object with details of a new student. Since you in reality only have one object you end up changing the values of that one object each time the loop runs. And adding that object to the array multiple times just creates multiple pointers to it. The solution to this issue is quite simple. Just create the object within the loop. Like this: ```JavaScript alert ("Hello"); var students = []; var tempNewStudentStorage; var finished; var questions = [ "What is the student's name?", "What Track(s) are they on?", "What achivement(s) have they gotten?", "What are their points?", ]; while (true) { var newStudent = { Name: "x", Track: "y", Achivement: 0, Points: 0, }; for (var i = 0; i < 4; i +=1) { tempNewStudentStorage = prompt(questions[i]); if (i === 0){ newStudent.Name = tempNewStudentStorage; } else if (i === 1){ newStudent.Track = tempNewStudentStorage; } else if (i === 2){ newStudent.Achievemnt = tempNewStudentStorage; } else if (i === 3){ newStudent.Points = tempNewStudentStorage; }; }; students.push(newStudent); finished = prompt("Are you done adding students? Y/N").toLowerCase(); while (finished.length > 1) { finished = prompt("Are you done adding students? Y/N").toLowerCase() }; if (finished === "y") { alert("Thank you for adding a new student!") break } else if (finished !== "y"){ continue; }; }; console.log(students); ``` That way you actually create a new object each time the loop runs, instead of reusing the object created at the start of the script. It's worth noting that Arrays and Functions also behave in the same way as I described above.