I have two objects one is obj1 and obj2. I need to contact the obj2 in obj1 details array.
const obj1 = {
name: 'test',
phone: '233123',
details: [{
address1: 'test233',
address2: 'testts'
},
{
address1: 'test3',
address2: 'testts'
}
]
}
const obj2 = {
address1: 'test4',
address2: 'testts443'
}
obj1['details'].push(obj2);
console.log(obj1)
I tried with this code obj1['details'].push(obj2); when I tried to return the obj1 its return below output I tried in Object assign also it's not working for me.
my output
obj1 = {
name:'test',
phone:'233123';
details: [
{
address1:'test233',
address2:'testts'
},
{
address1:'test3',
address2:'testts'
},
[{
address1:'test4',
address2:'testts443'
}]
]
}
my expected output is
obj1 = {
name:'test',
phone:'233123';
details: [
{
address1:'test233',
address2:'testts'
},
{
address1:'test3',
address2:'testts'
},
{
address1:'test4',
address2:'testts443'
}
]
}