Using Variables inside Collection

Hello everyone, hope everything is all right!!
So, i have a variable inside a collection that is an array of arrays, here is an example:


And i will insert this data using a patch/post request. But after it i want to slice it(take out the user already used),

var item = JSON.parse(pm.collectionVariables.get("arrayOfArrayUsers"));

var itemLess = item.slice(1)


pm.collectionVariables.set("arrayOfArrayUsers", itemLess);

but after it, the “” from it goes always and its like this:

So maybe i’m doing something wrong, or it’s losing its configuration somehow?

Hi @aerospace-candidate1,

You’re halfway there - you’re already using JSON.parse when getting the collection variable, indicating that you wish to retrieve structured data.

You just need to make the same update when setting the collection variable, in the final line of your example:

pm.collectionVariables.set("arrayOfArrayUsers", JSON.stringify(itemLess));

Now when this script runs against your original input, the result written back is still in nested array format:


Hopefully this helps to solve your problem :smiley:

1 Like

Thank you very much!