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:

[
    [
        "1",
    	"Matthew",
        "IT"
    ],
    [
        "2",	
        "breanna",	
        "RH"
    ],
]

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)

console.log("itemLess",itemLess);

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

but after it, the โ€œโ€ from it goes always and its like this:
2,breanna,RH

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:

image

Hopefully this helps to solve your problem :smiley:

1 Like

Thank you very much!