You have to create an object. Assign the values to the object. Then push it into the array:

var nietos = [];
var obj = {};
obj["01"] = nieto.label;
obj["02"] = nieto.value;
nietos.push(obj);
Answer from user3589620 on Stack Overflow
🌐
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 push method. let array = []; let obj = { name: 'Billy', age: 30, role: 'admin' }; array.push(obj); console.log(array); // [{name: 'Billy', age: 30, role: 'admin'}] As you can see, we simply pass the obj object to the push() method and it will add it to the end ...
Discussions

javascript - How can I push an object into an array? - Stack Overflow
Why do you need to use "01" as the key? What if I wanted to use nieto.label as the key? 2022-02-04T18:22:16.113Z+00:00 ... First you create the object inside of the push method and then return the newly created array. More on stackoverflow.com
🌐 stackoverflow.com
Help: Pushing new objects into an array in JavaScript
Currently in the "JavaScript Loops, Arrays and Objects". While working on the objective of simply creating a list of objects in an array and then printing them, I decided to challenge myself more. To this end I tried to create a prompt set up that will do the following: Ask a series of 4 questions. Take the answers and create a new student object. Take that new student object and push ... More on teamtreehouse.com
🌐 teamtreehouse.com
1
April 22, 2018
How do I push an array inside an object array
First, you have two different code versions. The one in the link and the one you pasted here. Which one should we be looking at · Second, what date array? I don’t see an array with the name date. Please be a little more clear about what you are trying to do · In the code in the link, the ... More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
1
0
March 18, 2022
How to push data to nested object in JavaScript
I think you've got it the wrong way around. The thing that you want to keep adding items to should be an array and each item should apparently be an object. var orders = { theOrderNum: [ { itemName: "Coffee", itemQty: 1 }, { itemName: "Chips", itemQty: 2 } ], theOtherOrderNum: [ { itemName: "Apples", itemQty: 2 }, { itemName: "Oranges", itemQty: 1 } ] }; orders.theOrderNum.push({ itemName: "Bananas", itemQty: 3 }); orders.theOtherOrderNum.push({ itemName: "Pears", itemQty: 2 }); You could also do this var orders = { theOrderNum: { Coffee: { itemQty: 1 }, Chips: { itemQty: 2 } }, theOtherOrderNum: { Apples: { itemQty: 2 }, Oranges: { itemQty: 1 } } }; orders.theOrderNum.Bananas = 3; or even this var orders = { theOrderNum: { Coffee: 1, Chips: 2 }, theOtherOrderNum: { Apples: 2, Oranges: 1 } }; orders.theOrderNum.Bananas = 3; In those two options, each kind of item can only appear once in each order (with a certain quantity), which may or may not be what you want. More on reddit.com
🌐 r/learnjavascript
7
3
February 25, 2019
🌐
HostingAdvice
hostingadvice.com › home › how-to
JavaScript "Add to Array" Functions (push vs unshift vs others)
March 25, 2023 - You can also add multiple elements to an array using push(), as shown below:
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › push
Array.prototype.push() - JavaScript | MDN
Instead, we store the collection on the object itself and use call on Array.prototype.push to trick the method into thinking we are dealing with an array—and it just works, thanks to the way JavaScript allows us to establish the execution context in any way we want.
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.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-add-an-object-to-an-array-in-javascript
JavaScript- Add an Object to JS Array - GeeksforGeeks
The push() method adds objects to the end, unshift() adds to the beginning, and concat() combines arrays. The spread operator offers a modern way to append objects, while splice() allows insertion at specific indices.
Published   July 12, 2025
🌐
Vultr Docs
docs.vultr.com › javascript › examples › append-an-object-to-an-array
JavaScript Program to Append an Object to An Array
November 8, 2024 - Appending an object to an array ... requirements like immutability and coding style preferences. Use the push() method for a straightforward, in-place addition. Opt for the spread operator or concat() when you need to preserve ...
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-push-an-object-into-an-array-using-for-loop-in-javascript
How to Push an Object into an Array using For Loop in JavaScript ? - GeeksforGeeks
August 5, 2025 - JavaScript allows us to push an object into an array using a for-loop. This process consists of iterating over the sequence of values or indices using the for-loop and using an array manipulation method like push(), to append new elements to ...
🌐
Sentry
sentry.io › sentry answers › javascript › how to insert an item into an array at a specific index using javascript
How to insert an item into an array at a specific index using JavaScript | Sentry
January 30, 2023 - You can also use a for loop to loop through each item in an array, add each item to a new array, and insert an item at a specific index: ... const arr = ["walk the dog", "go shopping", "exercise"]; const index = 2; const value = "go to the ...
🌐
freeCodeCamp
freecodecamp.org › news › how-to-insert-an-element-into-an-array-in-javascript
Push into an Array in JavaScript – How to Insert an Element into an Array in JS
November 7, 2024 - This article will show you how to insert an element into an array using JavaScript. In case you're in a hurry, here are the methods we'll be discussing in depth in this article: // Add to the start of an array Array.unshift(element); // Add to the end of an array Array.push(element); // Add to a specified location Array.splice(start_position, 0, new_element...); // Add with concat method without mutating original array let newArray = [].concat(Array, element);
🌐
daily.dev
daily.dev › home › blog › get into tech › create array of objects javascript: a beginner's guide
Create Array of Objects JavaScript: A Beginner's Guide
December 22, 2025 - Here, we have a mix: two fruits by name, a true/false value, and an object (think of it as a box with more info inside). ... Learning about arrays is like learning to organize your shopping list better. They can hold all sorts of things, even lists within lists! This makes them a key part of using JavaScript. First, let's start by making an empty list where our cars will go: ... Now, let's add some cars to our list. Each car is like a mini-box with details inside it: cars.push({ make: "Toyota", model: "Corolla", year: 2022 }); cars.push({ make: "Tesla", model: "Model 3", year: 2021 });
🌐
Sencha
sencha.com › home › blog › how to add elements to the beginning of an array in javascript (2026 guide)
How to Add Elements to the Beginning of an Array in JavaScript (2026 Guide)
March 14, 2024 - Adding elements to the beginning of an array, technically called prepending, is a fundamental operation in JavaScript programming. Unlike appending elements to the end using push(), prepending requires shifting all existing elements to higher indices, which has significant implications for performance and memory usage.
🌐
W3Schools
w3schools.com › js › js_array_methods.asp
JavaScript Array Methods
When you work with arrays, it is easy to remove elements and add new elements. ... Popping items out of an array, or pushing items into an array.
🌐
GitHub
github.com › zloirock › core-js
GitHub - zloirock/core-js: Standard Library
We have no bulletproof way to polyfill this Error.isError / check if the object is an error, so it's an enough naive implementation. Modules es.array.from, es.array.from-async, es.array.is-array, es.array.of, es.array.copy-within, es.array.fill, es.array.find, es.array.find-index, es.array.find-last, es.array.find-last-index, es.array.iterator, es.array.includes, es.array.push, es.array.slice, es.array.join, es.array.unshift, es.array.index-of, es.array.last-index-of, es.array.every, es.array.some, es.array.for-each, es.array.map, es.array.filter, es.array.reduce, es.array.reduce-right, es.array.reverse, es.array.sort, es.array.flat, es.array.flat-map, es.array.unscopables.flat, es.array.unscopables.flat-map, es.array.at, es.array.to-reversed, es.array.to-sorted, es.array.to-spliced, es.array.with.
Starred by 25.5K users
Forked by 1.7K users
Languages   JavaScript
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › objects: the basics
Objects
2 weeks ago - Help to translate the content of this tutorial to your language! ... As we know from the chapter Data types, there are eight data types in JavaScript. Seven of them are called “primitive”, because their values contain only a single thing (be it a string or a number or whatever). In contrast, objects are used to store keyed collections of various data and more complex entities.