Given the following array (nested), I'm unsure how to loop through these nested arrays using map to produce the below result.
const qry = [
{
qryNm: "A",
qryResult: "",
qryWhere: [
{
qryReqs: [
{
col: "name",
op: "=",
colVal: "tom"
},
{
col: "country",
op: "=",
colVal: "germany"
}
]
},
{
qryReqs: [
{
col: "name",
op: "=",
colVal: "sally"
},
{
col: "country",
op: "=",
colVal: "italy"
}
]
}
]
},
{
qryNm: "B",
qryResult: "",
qryWhere: [
{
qryReqs: [
{
col: "name",
op: "=",
colVal: "kirk"
},
{
col: "country",
op: "=",
colVal: "sweeden"
}
]
},
{
qryReqs: [
{
col: "name",
op: "=",
colVal: "grace"
},
{
col: "country",
op: "=",
colVal: "usa"
}
]
}
]
}
]
I need to loop through the above array and produce the following result:
(name = 'tom' and
country = 'germany')
or
(name = 'sally' and
country = 'italy')
and assign this value to qryResult within the qry array, for that qryNm, i.e.:
qryResult = "(name = 'tom' and country = 'germany') or (name = 'sally' and country = 'italy')";
Obviously, this qryResult will need to be processed for every array element within the qry array.
So for every qryReqs within the array qryWhere, break this as an "OR" condition.
Having the three level of arrays, I'm unsure how to achieve my result.
I realise that I need to use:
qry.map((q, i) => (
// unsure from here
))
Any help/guidance would be great.