The ask here is, when we use map function over an array, it iterated the # of times the total objects present, we use $$ for iteration count, now after each object iteration, the $$ gets reset to 0, but I want for next iteration the iteration count should move ahead with +1 instead of 0.
I have a request payload as:
[
{
"id": 1
},
{
"id": 2
},
{
"id": 3
},
{
"id": 4
}
]
The final response expected is:
{
"products": [
{
"iterater": 1,
"child": [
{
"childIterater": 2
},
{
"childIterater": 3
},
{
"childIterater": 4
},
{
"childIterater": 5
}
]
},
{
"iterater": 6,
"child": [
{
"childIterater": 7
},
{
"childIterater": 8
},
{
"childIterater": 9
},
{
"childIterater": 10
}
]
},
{
"iterater": 11,
"child": [
{
"childIterater": 12
},
{
"childIterater": 13
},
{
"childIterater": 14
},
{
"childIterater": 15
}
]
},
{
"iterater": 16,
"child": [
{
"childIterater": 17
},
{
"childIterater": 18
},
{
"childIterater": 19
},
{
"childIterater": 20
}
]
}
]
}
products is mapped over request payload and that is why there are 4 objects, inside products, child is again mapped with request payload, so each object again has 4 objects.