I have an object like this, and I want to simply add items to it using pure JavaScript. Because the following object is not an array and it has name defined.
Such as "John" and further age and feedback. How can I add similar object to it in Javascript?
var emps = {
"John": {
"age": "30",
"feedback": "There is a reason behind this"
},
"Amy": {
"age": "22",
"userComment": "No reasons"
}
};
I want to add Rob now to it keeping the structure same but through JavaScript code.
"Rob": {
"age": "42",
"userComment": "No reasons"
}
emps.push() //Something to it. I am confused with it the "Name" being id.
It should become:
var emps = {
"John": {
"age": "30",
"feedback": "There is a reason behind this"
},
"Amy": {
"age": "22",
"userComment": "No reasons"
},
"Rob": {
"age": "42",
"userComment": "No reasons"
}
};