JSON Add an Object

Adding Object to Array

Use Array.push() inbuilt javascript method to add an object to an array.

In the following example, we will add an object (jack) to an array (data) by using Array.push() inbuilt javascript method.


HTML Editor
<!DOCTYPE html> <html lang="en-US"> <body> <h1>JSON Adding an Object</h1> <button onclick="myFunction()">Click Me</button> <script> var data = [ { "name": "Mike", "age": 36 } ] var jack = {"name": "Jack", "age": 28}; function myFunction(){ // Adding jack (object) to data data.push(jack); console.log(data); } </script> </body> </html>



Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author