# Push an object to an array in JavaScript

By Atta Ur Rehman Shah (https://attacomsian.com/about). Published Aug 7, 2022, updated Jun 10, 2023. Topics: JavaScript.
Canonical URL: https://attacomsian.com/blog/javascript-push-object-to-array

> A quick guide to learning how to push an object to an array using the Array.push() method in JavaScript.

To add an object to an array in JavaScript, you can follow these steps:

1. Use the `Array.push()` method.
2. Provide one or more objects as arguments.
3. This method appends one or more elements at the end of the array and returns the new length.

Here's an example:

```javascript
const users = []

const obj = {
  name: 'John Doe',
  age: 23
}

users.push(obj)

console.log(users)
// [ { name: 'John Doe', age: 23 } ]
```

You can also add multiple objects to an array by passing them as separate arguments to the `Array.push()` method, as demonstrated below:

```javascript
const users = []

const obj1 = { name: 'John Doe', age: 23 }
const obj2 = { name: 'Jane Doe', age: 31 }
const obj3 = { name: 'Alex Lee', age: 18 }

users.push(obj1, obj2, obj3)

console.log(users)
// [
//   { name: 'John Doe', age: 23 },
//   { name: 'Jane Doe', age: 31 },
//   { name: 'Alex Lee', age: 18 }
// ]
```

For further information on JavaScript arrays and storing multiple pieces of information in a single variable, you can read [this article](https://attacomsian.com/blog/javascript-arrays).
