我正在尝试从一个简单的数组中创建一个深层嵌套的 JS 对象。棘手的部分是数组中的下一项应始终添加到前一项。
假设我的数组如下所示:
const filters = [
[
{brand: {eq: 'BMW'}},
{brand: {eq: 'AUDI'}}
],
[
{year: {eq: '2019'}},
{year: {eq: '2020'}}
],
[
{country: {eq: 'CH'}},
{country: {eq: 'DE'}}
]
]
Run Code Online (Sandbox Code Playgroud)
如何获得具有该结构的对象?
query: {
and: {
or: [
{ brand: { eq: 'BMW' } },
{ brand: { eq: 'AUDI' } }
],
and: {
or: [
{ year: { eq: '2019' } },
{ year: { eq: '2020' } }
],
and: {
or: [
{ country: …Run Code Online (Sandbox Code Playgroud)