Add Delete Find Filter ForEach IndexOf Map Chain Functions BrowserStorage Promise Back
Logo image

Add Object To Array Of Objects


Suppose you want to create a form to add a list of person's name & phone number.

You can store the data in append to javascript object array & use Array.unshift to add to front of array & Array.push to the back of array.


Copy the code below & save file as object.html:



Explaination:

We declare constructor with keyword "new Object()" and added it to the front & back of the array.

In Javascript almost everything is an object, even a function can be declared as with the keyword "new".

See this example:.

function myObject(a, b) {

this.name = a;

this.age = b;

this.all = a + " " + b;

return document.getElementById("out").innerHTML = this.all; }

let n = new myObject("Jack", 25);