WEB TUTORIALS
PRACTICE EXAMPLES
HTML REFERENCES
CSS REFERENCES
PHP REFERENCES

How to Add an Object to an Array in JavaScript

Topic: JavaScript / jQueryPrev|Next

Answer: Use the push() Method

You can simply use the Array push() method to add an object to an array in JavaScript.

Let's try out the following example to understand how it basically works:

// Sample array
var persons = ["Peter", "Clark", "John"];

// Sample object
var obj = {name: "Harry", age: 18};

// Adding object to the array
persons.push(obj);

console.log(persons);

Related FAQ

Here are some more FAQ related to this topic:

Bootstrap UI Design Templates Property Marvels - A Leading Real Estate Portal for Premium Properties