VOOZH about

URL: https://www.geeksforgeeks.org/javascript/how-to-push-an-array-into-the-object-in-javascript/

⇱ How to Push an Array into Object in JavaScript? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to Push an Array into Object in JavaScript?

Last Updated : 12 Jul, 2025

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() Method

The 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.

Syntax

arr.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.


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.


Output
[ 'Geeks', 'for', 'Geeks' ]

Example 3: You can also add multiple arrays or elements to the object’s array property using the push() function.


Output
[ [ 'Hello', 'World', '!!!' ] ]

Supported Browsers

  • Chrome 1.0
  • Internet Explorer 5.5
  • Firefox 1.0
  • Safari
  • Opera

JavaScript 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