我想将多个数组合并成一个带有共享密钥的大数组。在Javascript中共享共享密钥上的多个数组合并
我已经试过什么:
var conditions = [];
if(aa != undefined)
{
conditions.push({ "query" : { "must" : { "aa" : "this is aa" } } });
}
if(bb != undefined)
{
conditions.push({ "query" : { "must" : { "bb" : "this is bb" } } });
}
上面的代码是给:
[
{
"query": {
"must": {
"aa": "this is aa"
}
}
},
{
"query": {
"must": {
"bb": "this is bb"
}
}
}
]
但我需要这样的:
[
{
"query": {
"must": [
{
"aa": "this is aa"
},
{
"bb": "this is bb"
}
]
}
}
]
我可以用PHP做但我需要在原生JavaScript或使用underscore.js
因为我从PHP转换我的应用程序的NodeJS –