Add New Object To Another Object's Object
var obj = {} obj.cats = {'name': 'Milo', 'age': 3} // first item Object.assign(obj.cats, {'name': 'Simba', 'age': 2}) // add new item to obj.cats console.log(obj) // result one
Solution 1:
You can use an array of objects:
var obj = {}
obj.cats = [{name: 'Milo', age: 3}] // first item
obj.cats.push({name: 'Simba', age: 2}) // add new item to obj.catsconsole.log(obj) // result two items in obj.cats (Milo & Simba)
Post a Comment for "Add New Object To Another Object's Object"