Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JavaScript Add an Object to an Array</title> </head> <body> <script> // Sample array var persons = ["Peter", "Clark", "John"]; // Sample object var obj = {name: "Harry", age: 18}; // Adding object to the array persons.push(obj); // Printing array on web page document.write(JSON.stringify(persons)); </script> </body> </html>