I am trying to parse the response data and getting the values for the "id". Since I am expecting multiple values for the same response I am putting it into an array. Inside a for loop I increment the array with the index set to i. Each of these values i need to pass it to a global variable like var_id0, var_id1... var_idn.
Can the numeric against the global name "var_id" be incremented inside the for loop?
I looked up multiple examples but none are showing me if such a thing can be done when setting the global variable.
var index_id= [];
var jsonData = JSON.parse(responseBody);
for (var i = 0; i < jsonData.list.length; i++) {
var counter = jsonData.list[i];
index_id[i] = counter.id;
pm.globals.set("var_id"[i], index_id[i]) <<-- How can this be achieved.
//pm.globals.set("variable name", "variable value") --> Actual syntax.
}
My expectation is that till the end of the for loop is reached, with each loop the global variable name, will be incremented by 1 and the corresponding value will be set. For eg:
var_id1 = "700" var_id2 = "800"...