Hi Raj,
Welcome to the k6 community forum.
I’m happy you already found a solution, I provide one more alternative.
Considering the response and the original example you posted seems you need a method for picking an item from the SharedArray
using a dynamic index without specific restrictions. As you have seen, a SharedArray can be accessed like a native JS array.
If the randomness is not a strict requirement then you could consider using the execution context __ITER variable. If you expect a data.length
smaller than iterations use it with a modulo
function.
Here an example:
var payload = data[__ITER % data.length]
I would also encourage you to read the When parameterizing data, how do I not use the same data more than once in a test? - #2 by mark thread where there are explained more advanced use cases and details for the same class of your question.