[英]How to merge two object of array lists in one array list in JavaScript
I'm trying to mix this objects which contain an array: 我正在尝试混合包含数组的对象:
var a = {[
{...},
{...},
{...}
]};
var b = {[
{...},
{...},
{...}
]};
in one level array: 在一个级别数组:
[
{...},
{...},
{...},
{...},
{...},
{...}
];
In JavaScript, I'm trying this without success: 在JavaScript中,我正在尝试这个没有成功:
var arr = a.concat(b);
because this gives me: 因为这给了我:
[
{[
{...},
{...},
{...}
]},
{[
{...},
{...},
{...}
]}
]
how can I obtain one level array? 我怎样才能获得一个级别的数组?
That's because a
and b
are not arrays. 那是因为
a
和b
不是数组。 Assuming you can modify the json format (and you should as it's not valid) you could change it for this 假设您可以修改json格式(并且因为它无效),您可以为此更改它
var a = [
{...},
{...},
{...}
];
var b = [
{...},
{...},
{...}
];
Then your code would work just fine 然后你的代码就可以了
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.