Pushing data to global vars array

Hello guys,

I have a issue when using the globalThis.VARS. I can assign a value to the for example globalThis.VARS[“orgId”] and then reuse it.

But I would like to assign a array to globalThis.VARS[“orgId”] and push to it data.

Is that possible?
Thanks

Hi @Lumca, Welcome to the community forum!

It is usually useful to provide what you tried in order for whoever is helping you guide you back to a solution.

From a very quick try

globalThis.Vars = {}
globalThis.Vars["orgId"] = []

export default () => {
  globalThis.Vars["orgId"].push("something")
  console.log(globalThis.Vars["orgId"])
}

Does work.

Though I would recommend not just continuously adding more data to a global variable as that will use more and more memory as times goes on. If you just put 10, 100 or even 1000 items - that likely is fine. But if you just keep adding stuff and make 1 million iterations that will likely have negative consequences for your test.

Also, a reminder that this global variables are per VU and so this data will not be shared between VUs and or executions of setup and teardown as those run in separate VUs as well.

Hope this helps you!