How to Push an Array into Object in JavaScript? Last Updated : 09 Jan, 2025 Comments Improve Suggest changes Like Article Like Report To push an array into the Object in JavaScript, we will be using the JavaScript Array push() method. First, ensure that the object contains a property to hold the array data. Then use the push function to add the new array in the object.Understanding the push() MethodThe array push() method adds one or more values to the end of the array and returns the new length. This method changes the length of the array. But here we will use this function to push the whole array into an object.Syntaxarr.push(element1[, ...[, elementN]])An array can be inserted into the object with push() function, below examples illustrate the above approach:Example 1: This example demonstrates adding an array into the object using the push method. JavaScript // Creating a JS object to add array into it let Obj = { arrayOne: [], arrayTwo: [] }; // Array to be inserted let arraynew = ['Geeks', 'for', 'Geeks']; // Push an array to object Obj.arrayOne.push(arraynew); console.log(Obj.arrayOne); Output[ [ 'Geeks', 'for', 'Geeks' ] ] We can also push the array elements inside the object instead of pushing the complete array with the help of spread operator.Example 2: This example adds multiple elements to the object’s array property using the push() function. JavaScript // Creating a JS object to add array into it let Obj = { arrayOne: [], arrayTwo: [] }; // Array to be inserted let arraynew = ['Geeks', 'for', 'Geeks']; // Push an array items to object Obj.arrayOne.push(...arraynew); console.log(Obj.arrayOne); Output[ 'Geeks', 'for', 'Geeks' ] Example 3: You can also add multiple arrays or elements to the object’s array property using the push() function. JavaScript // Creating a JS object to add array into let Obj = { arrayOne: ['Geeks', 'for', 'Geeks'], arrayTwo: [] }; // Array to be inserted let arraynew = ['Hello', 'World', '!!!']; // Pushing of array into arrayTwo Obj['arrayTwo'].push(arraynew); console.log(Obj.arrayTwo); Output[ [ 'Hello', 'World', '!!!' ] ] Supported BrowsersChrome 1.0Internet Explorer 5.5Firefox 1.0SafariOperaJavaScript is best known for web page development but it is also used in a variety of non-browser environments. You can learn JavaScript from the ground up by following this JavaScript Tutorial and JavaScript Examples. Comment More infoAdvertise with us Next Article How to Push an Array into Object in JavaScript? V vishodushaozae Follow Improve Article Tags : JavaScript Web Technologies javascript-object Similar Reads How to create an object with prototype in JavaScript ? In this article, we will discuss object creation & prototypes, along with understanding the different ways for object creation & their implementation through the examples. Prototypes are the mechanism by which objects in JavaScript inherit features from another object. A prototype property i 4 min read How to declare object with computed property name in JavaScript ? In this article, we learn how to declare an object with a computed property name. Before beginning this article, we have to know about the javascript objects. Computed Property Names: The ES6 computed property names feature allows us to compute an expression as a property name on an object. Javascri 2 min read How to add and remove properties from objects in JavaScript ? We will try to understand how to add properties to an object and how to add or remove properties from an object in JavaScript.Before we go and see the addition and removal of properties from an object let us first understand the basics of an object in JavaScript.Object:An object in JavaScript is a c 6 min read How to check if a value is object-like in JavaScript ? In JavaScript, objects are a collection of related data. It is also a container for name-value pairs. In JavaScript, we can check the type of value in many ways. Basically, we check if a value is object-like using typeof, instanceof, constructor, and Object.prototype.toString.call(k). All of the ope 4 min read JavaScript - Convert Two-Dimensional Array Into an Object Here are the different methods to convert the two-dimensional array into an object in JavaScript.1. Using a for LoopThe simplest way to convert a two-dimensional array into an object is by iterating through the array using a for loop and assigning key-value pairs.JavaScriptconst a = [['name', 'Abhay 2 min read How to get all the methods of an object using JavaScript? In this article, we will learn how to get all the methods of an object using JavaScript. In JavaScript, we can get all the methods of an object by iterating over each object and checking if its property value is a function. An HTML document contains some methods and the task is to get all methods of 2 min read How to implement a filter() for Objects in JavaScript ? In this article, we will learn how to implement a filter() for Objects in JavaScript. In JavaScript, the filter() method is a built-in function for the array, not for the object. The filter() method outputs all the elements of an array that pass a specific test or satisfies a specific function. The 3 min read How to add a property to a JavaScript object using a variable as the name? In JavaScript, you can dynamically add a property to an object using a variable as the name. This allows you to create flexible and dynamic objects based on runtime values, enhancing code reusability and adaptability. There are several methods that can be used to add a property to a JavaScript objec 2 min read How to Create Dynamic Values and Objects in JavaScript? In JavaScript, you can choose dynamic values or variable names and object names and choose to edit the variable name in the future without accessing the array, Dynamic values and objects in JavaScript allow changing, accessing, or creating values and object properties at runtime for flexibility and 3 min read JavaScript - Print Object by id in an Array of Objects Here are the various methods to print objects by id in an array of objects in JavaScript1. Using Array.filter() MethodThe Array.filter() method, creates a new array containing only the object with the specified ID. JavaScriptconst a = [ { id: 1, name: "Alia" }, { id: 2, name: "Dua" }, { id: 3, name: 3 min read Like