# Remove " from global variable, re-use in same request

**URL:** <https://community.postman.com/t/remove-from-global-variable-re-use-in-same-request/52109>\
**Category:** Help Hub\
**Tags:** variables, globals\
**Created:** [September 20, 2023, 7:54pm UTC](https://community.postman.com/t/remove-from-global-variable-re-use-in-same-request/52109 "2023-09-20T19:54:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![normgean](https://avatars.discourse-cdn.com/v4/letter/n/74df32/32.png) [@normgean](https://community.postman.com/u/normgean)\
**Post date:** [September 20, 2023, 7:54pm UTC](https://community.postman.com/t/remove-from-global-variable-re-use-in-same-request/52109/1 "2023-09-20T19:54:54Z")

</div>

in my 1st request under **Tests** i have the following to get a value and add it as a global variable for later use

```auto
var jsonData = pm.response.json();
var workplaceNumbers = [];

jsonData.workplaces.forEach(function(workplace) {
    var workplaceNumber = JSON.stringify(workplace.workplaceNumber);
    workplaceNumbers.push(workplaceNumber);
});
pm.globals.set("workplaceNumbers", (workplaceNumbers));

```

and this is an example of what workplaceNumbers saves: “1017703443”

in my 2nd request under **Pre-request Script** i try to remove the double-quotes, {{workplaceNumbers1}} is part of the Url of this 2nd request and double-quotes are an issue

```auto
// "Retrieve the saved "workplaceNumbers" value from the variable"*
var workplaceNumbers = pm.globals.get("workplaceNumbers");

// "Remove the double quotes from the workplaceNumbers value"
var workplaceNumbers1 = workplaceNumbers.replace(/"/g, "");

// "Set the new global variable "workplaceNumbers1"
pm.globals.set("workplaceNumbers1", workplaceNumbers1);

```

i am stuck here with the following error  
**There was an error in evaluating the Pre-request Script:TypeError: workplaceNumbers.replace is not a function**

Please let me know if there is a better way of doing the above

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [September 20, 2023, 11:32pm UTC](https://community.postman.com/t/remove-from-global-variable-re-use-in-same-request/52109/2 "2023-09-20T23:32:45Z")

</div>

Hey @normgean 👋

Welcome to the Postman Community! :postman:

I’m not sure what the response payload looks like, an example of that would be great.

Would you need to do this `JSON.stringify()` here? That’s likely the step that’s adding the `"` around the stored array value.

> [@normgean](#):
>
> `JSON.stringify(workplace.workplaceNumber)`

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [September 21, 2023, 9:36am UTC](https://community.postman.com/t/remove-from-global-variable-re-use-in-same-request/52109/3 "2023-09-21T09:36:50Z")

</div>

Following on from Danny’s comment.

You need to use JSON.stringify when storing arrays and JSON.parse when retrieving them.

Hopefully this should sort the quotes issue.

If that doesn’t sort the issue, please paste an example response (with at least 2 records please).

I suspect you can also use the JavaScript filter function to get you the array of workPlaceNumber’s instead of the forEach loop. If you want help with that, then please post an example response.

On a side note, why are you setting this as a global variable instead of a collection or environment.

Do you really need this variable to be available to all of your collections in Postman.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [October 21, 2023, 9:37am UTC](https://community.postman.com/t/remove-from-global-variable-re-use-in-same-request/52109/4 "2023-10-21T09:37:47Z")

</div>

Closed on October 21, 2023, 9:37am UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
