In order to push an array into the object in JavaScript, we need to utilize the push() function. With the help of Array push function this task is so much easy to achieve.
push() function: 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. 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:
Javascript
<script>
var Obj = {
arrayOne: [],
arrayTwo: []
};
var arraynew = [ 'Geeks' , 'for' , 'Geeks' ];
Obj.arrayOne.push(arraynew);
alert(Obj.arrayOne);
</script>
|
Output:

Example 2:
Javascript
<script>
var Obj = {
arrayOne: [ 'Geeks' , 'for' , 'Geeks' ],
arrayTwo: []
};
var arraynew = [ 'Hello' , 'World' , '!!!' ];
Obj[ 'arrayTwo' ].push(arraynew);
alert(Obj.arrayTwo);
</script>
|
Output:

Supported Browsers: The supported browser by the Array Push() Function are listed below:
- Google Chrome 1.0
- Internet Explorer 5.5
- Mozilla 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.
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
26 Jul, 2021
Like Article
Save Article