How to create nested object using JavaScript?

Viewed 65

I want to make a registration form and push the data inside an object and then make that object nested into the main object. For example:

var userName = document.getElementById("uname");
var age = document.getElementById("age");

const Students = {}

function submit(){
    student1 = {
        "name":userName.value,
        "age":age.value
    }
    Students[userName.value] = student1;
    console.log(Students)
}

my question is in this code a single student1 object is appended to the main Students object how can we make it dynamic if another user registers the form another object will create with a different name and keep appending into the main object?

0 Answers
Related