I have two javascript object with data like this:
{
"data": [
{
"foo": "2388163605_10150954953808606",
"bar": {
"xyz": "123",
},
"name": {
"name": [
{
"content": 1,
"data": "some text",
"id": "2388163605"
}
]
},
},
{
"not_the_same": "other values",
"foo": "different",
"bar": {
"xyz": "123",
},
"name": {
"name": [
{
"content": 1,
"data": "some text",
"id": "2388163605"
}
]
},
}]
}
Second one:
{
"data": [
{
"foo": "123+09",
"bar": {
"xyz": "1adad0",
},
},
}]
}
as you can see, the properties etc vary a bit, and of course the values as well. Also they don't have the same number of items in them. I'm trying to merge them like this:
$.extend(true,posts, posts_object);
(posts and posts_objects contain the two objects)
I want to merge them into this:
{
"data": [
{
"foo": "2388163605_10150954953808606",
"bar": {
"xyz": "123",
},
"name": {
"name": [
{
"content": 1,
"data": "some text",
"id": "2388163605"
}
]
},
},
{
"not_the_same": "other values",
"foo": "different",
"bar": {
"xyz": "123",
},
"name": {
"name": [
{
"content": 1,
"data": "some text",
"id": "2388163605"
}
]
},
},
{
"foo": "123+09",
"bar": {
"xyz": "1adad0",
},
},
}]
}
However, this results in the data from the second object to overwrite the data of the first object. Is there any way to merge them but instead add the items from the second object to the first object?
.push()to extend thedata:array or something else like add a second data property and make it an array of those. Difficult to say for sure.