Send Array Index Value in JSON Request Body for Batch Operation using Runner

Here’s my problem scenario:

I have an array of 10K user_id. I need to send them in Request Body using Collection Runner. I need to send 100 user_ids in one request and I will loop through the request 100 times using Collection Runner.

RequestBody

"root": [
    {
        "id": "{{currentId[0]}}",
        "type": "user",
    },
    {
        "id": "{{currentId[1]}}",
        "type": "user",
    },
    {
        "id": "{{currentId[2]}}",
        "type": "user",
    },
    .
    .
    97 times more
    .
    .
],

Pre-Request Script:

const actualIdList = [1,2,3,4,....10000];
let idList = pm.collectionVariables.get("idList");

if(!idList || idList.length == 0) {
    idList = actualIdList;
}

let currentId = []
if(idList.length >= 10) {
    for(let i = 0; i < 10; i++) {
        currentId[i] = idList.shift();
        pm.collectionVariables.set(`currentId[${i}]`, currentId[i]);
    }
}

pm.collectionVariables.set("idList", idList);

Tests:

const idList = pm.collectionVariables.get("idList");

if (idList && idList.length > 0){
    postman.setNextRequest("Sending for 100 User Ids");
} else {
    postman.setNextRequest(null);
}

pm.test("Status code is 200", function () {
    pm.response.to.have.status(200);
});

But using this syntax {{currentId[1]}} fails to parse the actual value when the raw request is posted to the API endpoint.

How to resolve this? Need your guidance. Thank you.
(I also see a similar question posted here)

The only solution that comes to my mind right now, is following but I dislike it.
(Typing out variable names in sequential order)

RequestBody

"root": [
    {
        "id": "{{currentId_0}}",
        "type": "user",
    },
    {
        "id": "{{currentId_1}}",
        "type": "user",
    },
    {
        "id": "{{currentId_2}}",
        "type": "user",
    },
    .
    .
    do this 97 times more
    .
    .
],

Pre-Request Script:

//Everything same as the above Pre-Request Script:

let currentId = []
if(idList.length >= 10) {
    for(let i = 0; i < 10; i++) {
        currentId[i] = idList.shift();
        pm.collectionVariables.set(`currentId_${i}`, currentId[i]);
    }
}

I just went with Python Scripting which resolved this issue for me.
Still any solution is welcome. Thanks

Your collection variables will be named.

currentId1, currentId2, etc.

So that is how they need to be referenced in the body.

{{currentId1}} not {{currentId[0]}

You do have an array called currentId, but you can’t reference them in the body using the handlebars (curly brackets) due to scope. The array is a local variable which will only be available to the pre-request script. It won’t be available to the body so they will be returned as “undefined”. (You can’t reference local or global variables in the body via its handlebars).

I also recommend you call the variable something else, so its clear on what is what.

Using variables | Postman Learning Center

Another option here is to have place holders in the body for these ID’s, and then directly overwrite them using the following method. This way the body will have the actual value and you are not replying on variable per se at this point.

const body = JSON.parse(pm.request.body.raw); // retrieve current body
// update the elements using your loop
// you should be able to target the element using the array index
// using the same index number that you are looping through your test data
pm.request.body.raw = body; // write back updated body