# Using Variables inside Collection

**URL:** <https://community.postman.com/t/using-variables-inside-collection/26413>\
**Category:** Help Hub\
**Tags:** variables, collections\
**Created:** [August 3, 2021, 8:38pm UTC](https://community.postman.com/t/using-variables-inside-collection/26413 "2021-08-03T20:38:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aerospace-candidate1](https://avatars.discourse-cdn.com/v4/letter/a/838e76/32.png) [@aerospace-candidate1](https://community.postman.com/u/aerospace-candidate1)\
**Post date:** [August 3, 2021, 8:38pm UTC](https://community.postman.com/t/using-variables-inside-collection/26413/1 "2021-08-03T20:38:37Z")

</div>

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:

```auto
[
    [
        "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),

```auto
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?

---

<div class="post-metadata">

**Author:** ![neilstudd](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/neilstudd/32/8213_2.png) [@neilstudd](https://community.postman.com/u/neilstudd)\
**Post date:** [August 4, 2021, 7:36am UTC](https://community.postman.com/t/using-variables-inside-collection/26413/2 "2021-08-04T07:36:33Z")

</div>

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](https://us1.discourse-cdn.com/getpostman/original/2X/3/3ccd8fd9d382bbd2490ed97fe82d4f7fa4478cef.png)

Hopefully this helps to solve your problem 😃

---

<div class="post-metadata">

**Author:** ![aerospace-candidate1](https://avatars.discourse-cdn.com/v4/letter/a/838e76/32.png) [@aerospace-candidate1](https://community.postman.com/u/aerospace-candidate1)\
**Post date:** [August 4, 2021, 6:51pm UTC](https://community.postman.com/t/using-variables-inside-collection/26413/3 "2021-08-04T18:51:36Z")

</div>

Thank you very much!
