我想將多個數組合併成一個帶有共享密鑰的大數組。在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 –