I'm trying to create a deep nested JS Object out of a simple array. The tricky part is that the next item in the array should always be added to the previous one.
Assuming my array looks like this:
const filters = [
[
{brand: {eq: 'BMW'}},
{brand: {eq: 'AUDI'}}
],
[
{year: {eq: '2019'}},
{year: {eq: '2020'}}
],
[
{country: {eq: 'CH'}},
{country: {eq: 'DE'}}
]
]
How can I get a Object with that structure?
query: {
and: {
or: [
{ brand: { eq: 'BMW' } },
{ brand: { eq: 'AUDI' } }
],
and: {
or: [
{ year: { eq: '2019' } },
{ year: { eq: '2020' } }
],
and: {
or: [
{ country: { eq: 'CH' } },
{ country: { eq: 'DE' } }
],
... and so on
}
}
}
},
How do I achieve to add a new "or" block to the previous "or" block?