I have two JavaScript objects as shown below:
const objOne = {
"firstname": "xzxz",
"lastname": "xzxzxzx"
};
const objTwo = {
"title": [
{
"name": "foo",
"table": "First"
},
{
"name": "bar",
"table": "Second"
}
]
};
I would like to merge them into a single object structure, combining the properties.
{
"firstname": "xzxz",
"lastname": "xzxzxzx",
"title": [
{
"name": "foo",
"table": "First"
},
{
"name": "bar",
"table": "Second"
}
]
}
My attempted solution so far is as follows:
let result = [];
results.push(objOne);
results.push(objTwo);
However, this approach creates an array with both objects instead of merging their properties.
[
{
"firstname": "xzxz",
"lastname": "xzxzxzx"
},
{
"title": [
{
"name": "foo",
"table": "First"
},
{
"name": "bar",
"table": "Second"
}
]
}
]